Ene Uran 638 Posting Virtuoso

You can download the matplotlib free from: http://matplotlib.sourceforge.net/
It has, amongst many other things, the module pylab that allows for high quality plotting of data. All you have to do is to feed it a list of x values and the corresponding list of y values calculated from the x data and you are ready to enjoy the plot in its separate window/frame. From there you can zoom the graph, drag the graph, change the margins, and save the graph to a popular image file like PNG.

Ene Uran 638 Posting Virtuoso

Nice to know that C# has gained popularity apart from the original MS Visual IDE. It can be used on Linux platforms using Mono instead of .NET. There is also an official language standard at:
http://www.ecma-international.org/publications/standards/Ecma-334.htm

I think the GUI capabilities are great.

Ene Uran 638 Posting Virtuoso

Very nice example of switch case!

Ene Uran 638 Posting Virtuoso

The small images you put on buttons and such are nice, but a real pain if you have to attach all those image files to your program. Python's base64 encoding module makes it easy to convert the binary image code to a string that you can simply make part of your program. Here is an example how to do this using the Tknter GUI toolkit.

Ene Uran 638 Posting Virtuoso

Please add justify='left' to the tk.Label arguments. The default text alignment is 'center' and that screws things up. My bad!

Ene Uran 638 Posting Virtuoso

Nothing fancy. just shows a simple monthly calendar in a Tkinter label. The trick is to use a fixed font so spaces take up the same area as numbers.

Ene Uran 638 Posting Virtuoso

Just a simple console blackjack game. The bread and butter code was written with lots of comments, so you can improve on it. Really, the most important part is figuring out when an ace is 11 in value and when it is a 1 in value, so you don't bust.

Ene Uran 638 Posting Virtuoso

Let's say you had a list of full names, where the name would consist of a title, followed by first, middle and last name, or maybe just title and last name. You can sort this list by last name only, by creating a temporary list of sublists of type [last name, full name].

Python makes all of this relatively easy. The last name element is obtained by splitting the full name into a list and using the last element of that list. When the temporary list of sublists is sorted, it is sorted by the first element in the sublist. Once the sort is done, simply recreate a list of the sublists' second element, removing the temporary last name item. I hope, I added enough comments in the code, so you can follow the logic.

Ene Uran 638 Posting Virtuoso

Just to let you kow, I added an edit feature to the database as requested by some folks.

Ene Uran 638 Posting Virtuoso

More or less a templet database that allows you to load, save, add, list, search, edit and delete data items. I used movies as an example, but you can easily change that to make a database of many other things.

Ene Uran 638 Posting Virtuoso

The snippet shows the use of a list of class instances to form a sortable and searchable database for solvents, or for that matter other chemicals. The list can be expanded and all the needed data added at the same time.

Ene Uran 638 Posting Virtuoso

The .h in windows.h stands for header, it is actually C not html. Header files are there to unclutter your code and make it easier to read and hopefully understand. So by nature, header files are hard to read and understand for a beginner.

Ene Uran 638 Posting Virtuoso

Just a short little C program to send beeps to the PC internal speaker. Beep(frequency_hrz, duration_ms) is a WinAPI function as is Sleep(ms).

Ene Uran 638 Posting Virtuoso

A list of tuples is easy to sort for items in the tuples. This snippet shows you how to sort a (character, frequency) tuple either by character or by frequency. One useful example would be the sorting and display of a list of (player, score) tuples, you might find in a game.

Ene Uran 638 Posting Virtuoso

I get these results on a Windows Xp machine:

Function while1() takes 9.358 microseconds/pass
Function for1() takes 10.075 microseconds/pass
Function for2() takes 10.604 microseconds/pass

Wonder why xrange() is even slower?

Ene Uran 638 Posting Virtuoso

Powers of 2 are closly linked to the position values of binary numbers. The most right position is 2 to the power 0 = 1 then goes to the left with 2 to the power 1 = 2, 2 to the power 2 = 4 and such. If you want to know that a number fits this sequence, you can use this litle code.

Ene Uran 638 Posting Virtuoso

What is "cat" and where does it come from?

Ene Uran 638 Posting Virtuoso

"Modify the program in Fig 2.21 so it uses only
integers for monetary values to calculate the compound
interest."
Why would you ever want to do that for?

Ene Uran 638 Posting Virtuoso

I have played with Python a little and find it refreshing compared to C++. Gone is the long list of header files and references to obscure libraries in the make/batch file for the compiler. Also gone are the "gotchya" memory leaks.

I have to get used to the fact that type declarations are by inference, and there is only one type of string/character object. Another thing to get used to is the indention of statement blocks to replace {} and the semicolons are gone!

Ene Uran 638 Posting Virtuoso

Ouch! Thanks Lingson, I overlooked that range() does not return a list in Python3. So I give you the correct version here:

# exploring multiple Tkinter check buttons
# check buttons allow more than one item to be selected/checked
# ene

try:
    # Python2
    import Tkinter as tk
except ImportError:
    # Python3
    import tkinter as tk

def cb_checked():
    # show checked check button item(s)
    label['text'] = ''
    for ix, item in enumerate(cb):
        if cb_v[ix].get():
            label['text'] += '%s is checked' % item['text'] + '\n'


root = tk.Tk()

mylist = [
'apple',
'orange',
'banana',
'pear',
'apricot'
]

# list(range()) needed for Python3
cb = list(range(len(mylist)))
cb_v = list(range(len(mylist)))
for ix, text in enumerate(mylist):
    # IntVar() tracks checkbox status (1=checked, 0=unchecked)
    cb_v[ix] = tk.IntVar()
    # command is optional and responds to any cb changes
    cb[ix] = tk.Checkbutton(root, text=text,
        variable=cb_v[ix], command=cb_checked)
    cb[ix].grid(row=ix, column=0, sticky='w')

label = tk.Label(root, width=20)
label.grid(row=ix+1, column=0, sticky='w')

# you can preset check buttons (1=checked, 0=unchecked)
cb_v[3].set(1)
# show initial selection
cb_checked()

root.mainloop()

Now it works with Python2 and Python3 as planned. I downloaded the Editra IDE, now I can easily check my code in both Python versions.

I will contact vegaseat to correct the sample code, since the error appears in both samples.

Ene Uran 638 Posting Virtuoso

Take a look at Python's audioop module in the manual.

Python has some additional modules like 'sunau', ' aifc' and 'wave' that offer sound file reading, writing and some 'rythmatic'.

Ene Uran 638 Posting Virtuoso
Gribouillis commented: Nice link. I will try it. +4
Ene Uran 638 Posting Virtuoso

A nice brain teaser to get to know Python, here are some hints:

"""wants dictionary object -->
{'toy301': ('Flying Kite', [('AB339',2),('DC302',2),('FR377',2),
('JK301),1),('YU301',1),('EE301',1),('FW301),1)])}
"""

# typical data line from a file
line = """\
toy301, Flying Kite, AB339:2,DC302:2,FR377:2,JK301:1,YU301:1,EE301:1,FW301:1
"""

# first split the line at the commas
list1 = line.split(",")
print(list1)

"""result -->
['toy301', ' Flying Kite', ' AB339:2', 'DC302:2', 'FR377:2',
'JK301:1', 'YU301:1', 'EE301:1', 'FW301:1\n']
"""

# next create a list of tuples from items that have ':'
tuple_list = []
for item in list1:
    # strip off trailing newline
    line = line.rstrip()
    if ':' in item:
        text, num = item.split(":")
        tuple_list.append((text, int(num)))

print(tuple_list)

"""result -->
[(' AB339', 2), ('DC302', 2), ('FR377', 2), ('JK301', 1),
('YU301', 1), ('EE301', 1), ('FW301', 1)]
"""

# now you are ready to piece together the dictionary object from
# parts in list1 and the tuple_list
Ene Uran 638 Posting Virtuoso

There is a working example of Tkinter's radio buttons and also a comparative look at check buttons at:
http://www.daniweb.com/forums/showpost.php?p=966368&postcount=58

Ene Uran 638 Posting Virtuoso

A quick look at Tkinter's radio and check buttons:

# exploring multiple Tkinter radio buttons
# radio buttons only allow one item to be selected/checked
# ene

try:
    # Python2
    import Tkinter as tk
except ImportError:
    # Python3
    import tkinter as tk

def rb_selected():
    # show checked/selected radio button item
    ix = rb_v.get()
    label['text'] = 'you selected %s' % mylist[ix]

root = tk.Tk()

# used by the radio buttons as index
rb_v  = tk.IntVar()

mylist = [
'apple',
'orange',
'banana',
'pear',
'apricot'
]

# list(range()) needed for Python3
rb = list(range(len(mylist)))
for ix, text in enumerate(mylist):
    # command is optional and responds to any rb changes
    rb[ix] = tk.Radiobutton(root, text=text, value=ix,
        variable=rb_v, command=rb_selected)
    rb[ix].grid(row=ix, column=0, sticky='w')

label = tk.Label(root, width=20)
label.grid(row=ix+1, column=0, pady=5, sticky='w')

# you can preset one radio button
# default is first button (ix=0)
rb_v.set(2)
# show initial selection
rb_selected()

root.mainloop()
# exploring multiple Tkinter check buttons
# check buttons allow more than one item to be selected/checked
# ene

try:
    # Python2
    import Tkinter as tk
except ImportError:
    # Python3
    import tkinter as tk

def cb_checked():
    # show checked check button item(s)
    label['text'] = ''
    for ix, item in enumerate(cb):
        if cb_v[ix].get():
            label['text'] += '%s is checked' % item['text'] + '\n'


root = tk.Tk()

mylist = [
'apple',
'orange',
'banana',
'pear',
'apricot'
]

# list(range()) needed for Python3
cb = list(range(len(mylist)))
cb_v = list(range(len(mylist)))
for ix, text in enumerate(mylist):
    # IntVar() tracks checkbox status (1=checked, 0=unchecked)
    cb_v[ix] = tk.IntVar()
    # command is optional and …
Ene Uran 638 Posting Virtuoso

OOOOOH, putpixel places an image? Or does it draw a dot?

I guess it's time to experiment...

An image is made up of dots.

Ene Uran 638 Posting Virtuoso

An enlightening look at Tkinter's grid layout manager:

# looking at the Tkinter grid() layout manager
#
# The size of a grid cell in a given row or column is
# determined by its largest widget.
#
# If you give a grid layout more space than it needs,
# it will fill this space from its center on out.
# A way around this is to use place() with a frame and
# then grid() within this frame.
#
# Grid does not have an anchor positioner like pack().
#
# You can use place() and grid(), but not pack() and grid()
# within the same container widget.
#
# You can put a child grid into a parent grid.
# Ene

try:
    # Python2
    import Tkinter as tk
except ImportError:
    # Python3
    import tkinter as tk

root = tk.Tk()
root.title('Grid layout')
root['bg'] = 'yellow'

b1 = tk.Button(root, text="Button1")
b2 = tk.Button(root, text="Button2", bg='green')
b3 = tk.Button(root, text="Button3")
b4 = tk.Button(root, text="Button4")
b5 = tk.Button(root, text="Button5")
b6 = tk.Button(root, text="Button6")
b7 = tk.Button(root, text="Button7", bg='blue')
# button b8 has a 3 row text
b8 = tk.Button(root, text="\nButton8\n", bg='red')

b1.grid(row=0, column=1)
# use sticky=tk.E+tk.W or sticky='ew'
b2.grid(row=1, column=0, columnspan=3, sticky='ew')
b3.grid(row=2, column=0, pady=5)
b4.grid(row=2, column=1)
# gives the entire column=2 padx=10 padding!
b5.grid(row=2, column=2, padx=10)
b6.grid(row=3, column=2)
# forces button b7 to take up padded space too
b7.grid(row=4, column=2, ipadx=10)
# button b8 has a 3 row text, so give it rowspan=3
b8.grid(row=5, column=0, rowspan=3, columnspan=3, sticky='ew')

# …
Ene Uran 638 Posting Virtuoso

Put 100 Southerners in a room and half of them will discover they're related, even if only by marriage.

Ene Uran 638 Posting Virtuoso

A mind is like a parachute, it only works when it is open.
-- Jesse Ventura

Ene Uran 638 Posting Virtuoso

"Cap'n Crunch's Peanut Butter Crunch" cereal with whole milk.

Ene Uran 638 Posting Virtuoso

The reality is that most students will use a Windows OS notebook because the games they buy work on Windows only. Now students in computer science, engineering and medical sciences, that are used to writing their own programs, are more inclined to use Linux.

Ene Uran 638 Posting Virtuoso

The best selling beer in the world used to be "Bud Light", the really watery stuff from Budwiser. However in November 2008 is was toppled by a Chinese beer called "Snow".

The monthly beer magazine Beeradvocate gave "Snow" a D describing it as "unimpressive" and "extremely drinkable, like water". So now you can see that the watered down stuff sells best!

Ene Uran 638 Posting Virtuoso

If you are specifically looking for the text line:
'you love me'
then sravan953 code works best.

leegeorg07 code using 'in' would also give you a positive with a line like:
'you love me not'
which may be misleading.

Ene Uran 638 Posting Virtuoso

Python31 includes Tkinter Tile extension ttk. That extension has a Treeview widget that can function as a multicolumn Listbox. Here ia an example, that you may have to simplify somewhat:

"""Demo based on the demo mclist.tcl included with tk source distribution."""

import tkinter as tk
import tkinter.ttk as ttk
import tkinter.font as tkFont

tree_columns = ("country", "capital", "currency")
tree_data = [
    ("Argentina",      "Buenos Aires",     "ARS"),
    ("Australia",      "Canberra",         "AUD"),
    ("Brazil",         "Brazilia",         "BRL"),
    ("Canada",         "Ottawa",           "CAD"),
    ("China",          "Beijing",          "CNY"),
    ("France",         "Paris",            "EUR"),
    ("Germany",        "Berlin",           "EUR"),
    ("India",          "New Delhi",        "INR"),
    ("Italy",          "Rome",             "EUR"),
    ("Japan",          "Tokyo",            "JPY"),
    ("Mexico",         "Mexico City",      "MXN"),
    ("Russia",         "Moscow",           "RUB"),
    ("South Africa",   "Pretoria",         "ZAR"),
    ("United Kingdom", "London",           "GBP"),
    ("United States",  "Washington, D.C.", "USD")
    ]

def sortby(tree, col, descending):
    """Sort tree contents when a column is clicked on."""
    # grab values to sort
    data = [(tree.set(child, col), child) for child in tree.get_children('')]

    # reorder data
    data.sort(reverse=descending)
    for indx, item in enumerate(data):
        tree.move(item[1], '', indx)

    # switch the heading so that it will sort in the opposite direction
    tree.heading(col,
        command=lambda col=col: sortby(tree, col, int(not descending)))

class App(object):
    def __init__(self):
        self.tree = None
        self._setup_widgets()
        self._build_tree()

    def _setup_widgets(self):
        msg = ttk.Label(wraplength="4i", justify="left", anchor="n",
            padding=(10, 2, 10, 6),
            text=("Ttk is the new Tk themed widget set. One of the widgets it "
                  "includes is a tree widget, which can be configured to "
                  "display multiple columns of informational data without "
                  "displaying the tree itself. This is a simple way to build "
                  "a listbox that has multiple columns. Clicking on the "
                  "heading …
Ene Uran 638 Posting Virtuoso

I think these two lines:
c= content(self,-1)
Main.View.Template.Age.__init__(self, parent,id,c)
present a catch22 situation
self comes from line2 and c comes from 1

Ene Uran 638 Posting Virtuoso

On a notebook that you take from class to class, Windows Vista is simply unacceptable since it takes at least five minutes to boot up and just about the same to shut down. I hope Windows 7 offers some drastic improvement. I could care less for silly stuff like Paint, Wordpad, Mediaplayer or Games. Those things are easy to get for free and of better quality from a number of good folks.

jephthah commented: 100% +12
Ene Uran 638 Posting Virtuoso

The problem is that North Korea is the least computerized nation on this planet. If all the inhabitants would have access to the internet, there would not be "Ruler-for-live".

Ene Uran 638 Posting Virtuoso

I had "Monster Ale" and "Bigfoot Ale", those are barley wine style ales that have IBUs as hight as 90. Not for wimps!

A lot of common US beers range from 10 to 30 IBUs, because hops are expensive.

Ene Uran 638 Posting Virtuoso

Just in the news:
North Korea's military is behind a series of cyber attacks against South Korean and U.S. websites that slowed or disabled access by saturating them with traffic this week, a South Korean news report said on Saturday.

Ene Uran 638 Posting Virtuoso

At this point you have to show us your code, so we can see how you configured the sizer.

Ene Uran 638 Posting Virtuoso

That code doesn't work :confused:

Works fine for me. What is your error message?

Ene Uran 638 Posting Virtuoso

Actually, I stayed the long weekend at the new 'M' Casino in Las Vegas, the first casino you see as you drive in from California. Very nice rooms, fantastic food, music, dancing, swimming, sunning and best of all, I ended up several hundred Dollars ahead. The have a bar there that has almost a hundred different beers on draft. Needless to say, my friends and I had a great time tasting suds.

Ene Uran 638 Posting Virtuoso

TAXPAYER'S LAMENT

Tax his cow, Tax his goat;
Tax his pants, Tax his coat;
Tax his crop, Tax his work;
Tax his ties, Tax his shirt;
Tax his chew, Tax his smoke (now ain't that the truth);
Teach him taxing is no joke.
Tax his tractor, Tax his mule;
Tell him, Taxing is the rule.
Tax his oil, Tax his gas (again ain't that the truth)
Tax his notes, Tax his cash (oh boy a pattern emerges);
Tax him good and let him know,
That after taxes, he has no dough.
If he hollers, Tax him more;
Tax him till he's good and sore.
Tax his coffin, Tax his grave,
Tax his sod in which he's laid.
Put these words upon his tomb,
"Taxes drove him to his doom."
After he's gone, we won't relax.
We'll still collect inheritance tax.

Ene Uran 638 Posting Virtuoso

Sweet and sour chicken on rice. A Sunkist orange soda.

Ene Uran 638 Posting Virtuoso

At least they don't put it on Google Earth or the top search page.

There is no MS Earth or they would do it.

Ene Uran 638 Posting Virtuoso

There is now an IBU - International Bitterness Unit for beer. Standard IPAs are around 45 to 55 - Arrogant Bastard is about 145+ EBUs.

I drink to that! I like my beer with a higher IBU than old wash water Coors.

Ene Uran 638 Posting Virtuoso

And you think MS isn't spying on your OS activities? Get real!

Ene Uran 638 Posting Virtuoso

There is a much higher chance that your luggage ends up at another airport!

Ene Uran 638 Posting Virtuoso

Yeah, I kinda don't like the idea of google making an os... I can see google becoming an open source version of microsoft, trying to dominate every single market it see's.
I don't think windows seven will run vary well on my poor little aspire one, so I have to use linux (or buy a copy of windows xp becouse all we have is vista disks lying around the house.)

My little Aspire1 came with XP installed. God bless it!

But the basic problem with any Windows OS, it's like Swiss Cheese to malware attacks.

Ene Uran 638 Posting Virtuoso

I cannot put a vertical toolbar inside of a miniframe?

Sure you can, I understood you wanted to turn a miniframe into a toolbar. Here is an example you can play with:

# a wxPython general mini frame
# wx.MiniFrame() has a smaller title bar with title and exit x

import wx

class MyMiniFrame(wx.MiniFrame):
    def __init__(self, parent, mytitle, mysize):
        wx.MiniFrame.__init__(self, parent, wx.ID_ANY, mytitle,
            pos=(30, 50), size=mysize, style=wx.DEFAULT_FRAME_STYLE)
        self.control = wx.TextCtrl(self, 1, style=wx.TE_MULTILINE)

        # ToolBar at the top of the window
        toolbar = wx.ToolBar(self, -1, style=wx.TB_VERTICAL)
        toolbar.SetToolBitmapSize(size=(32,32))
        # pick a toolbar image file you have
        image_file = "new.png"
        image1 = wx.Bitmap(image_file)
        toolbar.AddSimpleTool(wx.ID_NEW, image1,
            "New", " New text")
        toolbar.Realize()
        self.SetToolBar(toolbar)


app = wx.App(0)
# create a MyFrame instance and show the frame
MyMiniFrame(None, 'the title', (400, 300)).Show()
app.MainLoop()