When all think alike, no one is thinking.
-- Walter Lippman
ZZucker 342 Practically a Master Poster
ZZucker 342 Practically a Master Poster
Nick Evan commented: haha :D +8
When all think alike, no one is thinking.
-- Walter Lippman
A note to John McCain's best buddy Phil Gramm:
"I feel better after I wine a little."
Looks like you need something simple like this:
import Tkinter as tk
def change_labels():
label1.config(text='I need someone real bad.')
label2.config(text='Are you real bad?')
root = tk.Tk()
label1 = tk.Label(root, text='Be alert.', width=50)
label2 = tk.Label(root, text='The world needs more lerts.', width=50)
button = tk.Button(root, text="Change Labels", command=change_labels)
# position the widgets
label1.grid(row=0, column=0, pady=5)
label2.grid(row=1, column=0, pady=5)
button.grid(row=2, column=0, pady=15)
root.mainloop()
Create a frame in your top window and put your widgets on that. A frame destroy will destroy the frame and the widgets on it. Now you can create a new frame and widget set.
Declaring your variable global has certain dangers, particularly when the variable name is simple. Not good coding practice!
You have to let your function return something and assign it after the call:
something = 1
def dosomething():
something = 2
return something
print something
something = dosomething()
print something
I'm gracious that my brother Jeb is concerned about the hemisphere as well.
-- Jeb's brother George
If air travel is so safe, why do you leave from a terminal?
The average person can live 11 days without water.
One day a perfect man and a perfect woman were driving in their perfect car. They saw an elf by the side of the road, being the perfect people they were, they picked him up.
Well as the perfect man and the perfect woman were driving with the elf, somehow they got into an accident. Two people died and one lived.
Who died and who lived?
The perfect woman, because the perfect man and elves aren't real.
Maybe the younger generation will finally start voting!
Windows supports real multitasking, it can boot and crash simultaneously.
I love my country, it's the government I fear!
He also said, "I'm the master of low expectations."
What other purposes would you do in a church?
One of our neighborhood churches was converted into a dance studio.
I like her pictures of dance!
German chocolate cake and a steaming hot mug of Kaffee Wien mit Schlag.
Research shows that one in seven Americans do not own a cell phone.
Those are the people who actually drive in the proper lane.
if you're voting for mccain, you're pretty much voting for his vp, he's so old he's gonna die in office.
He will most likely outlive many of the old pharts that vote for him!
- Once you're in heaven, do you get stuck wearing the clothes you were
buried in for eternity?
Do you think those clothes will last for an eternity?
My friends, more commerce will solve all of our problems! Hey Lieberman, wonder what an Iranian looks like? Are them soonies or she-ites?
Just imagine, someday I might be able to write such an important memo to my underlings, I mean associates, I mean partners, I mean coworkers, I mean colleagues, I mean friends, ...
These are the name, age arguments of that particular instance linking back to the superclass. In other words, each inherited superclass is unique to that instance.
This short code sample shows how to add an exit confirm to your wxPython program, from either a menu exit or the title bar exit:
# confirm exit of a wxPython program
import wx
class MyFrame(wx.Frame):
def __init__(self, parent, mytitle, mysize):
wx.Frame.__init__(self, parent, wx.ID_ANY, mytitle, size=mysize)
# create a status bar at the bottom
self.CreateStatusBar()
self.SetStatusText("Click on File")
menu = wx.Menu()
# just one item to test exit confirm
# the optional & allows you to use alt/x
# the last string argument shows in the status bar on mouse_over
menu_exit = menu.Append(wx.ID_ANY, "E&xit", "Exit the program")
# create a menu bar at the top
menuBar = wx.MenuBar()
# the & allows you to use alt/f
menuBar.Append(menu, "&File")
self.SetMenuBar(menuBar)
# bind the menu events to an action
self.Bind(wx.EVT_MENU, self.onMenuExit, menu_exit)
# responds to exit symbol x on frame title bar
self.Bind(wx.EVT_CLOSE, self.onCloseWindow)
def onMenuExit(self, event):
# triggers wx.EVT_CLOSE event and hence onCloseWindow()
self.Close(True)
def onCloseWindow(self, event):
# dialog to verify exit
dlg = wx.MessageDialog(self, "Want to exit?", "Exit",
wx.YES_NO|wx.ICON_QUESTION)
if dlg.ShowModal() == wx.ID_YES:
self.Destroy()
dlg.Destroy()
app = wx.App(0)
# create the MyFrame instance and then show the frame
MyFrame(None, 'Confirm exit', (400, 300)).Show()
app.MainLoop()
Zoe
Mankind must put an end to war, or war will put an end to mankind.
-- John F. Kennedy
Saving is a fine thing. Especially when your parents have done it for you.
Make crime pay. Become a Lawyer.
A man was in a bad accident and was injured. But the only permanent damage he suffered was the loss of both ears, which made him very self-conscious. However, he received a large sum of money from his insurance company.
It was always his dream to own his own business, so he went out and purchased a small, but expanding computer firm. But he realized that he had no business knowledge at all, so he decided that he would have to hire someone to run the business. He picked out three top candidates, and interviewed each of them. The last question of the interview was always the same.
"Do you notice anything unusual about me?" he asked the first candidate.
"Yes. You have no ears."
He quickly eliminated the first candidate.
"Do you notice anything unusual about me?" he asked the second candidate.
"Yes. You have no ears."
He quickly eliminated the second candidate.
"Do you notice anything unusual about me?" he asked the third candidate.
"Yes. You're wearing contacts."
Thinking he had found the man for the job he said, "That's correct. How did you know?"
"You can't wear glasses if you don't have any freakin' ears."
Are European after drinking a lot of beer?
Blueberries and cream.
As far as I understand it, Python has a very efficient builtin memory manager and user memory allocation is not need or wanted.
Actually a bubble sort will do exactly what you want:
# follow the progression of a bubble sort
def bubble_sort(list1):
swap_test = False
for i in range(0, len(list1) - 1):
for j in range(0, len(list1) - i - 1):
if list1[j] > list1[j + 1]:
# do a tuple swap
list1[j], list1[j + 1] = list1[j + 1], list1[j]
swap_test = True
if swap_test == False:
break
print list1
list1 = [8, 10, 6, 7, 4, 5, 9, 1, 4, 7]
bubble_sort(list1)
"""
output --->
[8, 6, 7, 4, 5, 9, 1, 4, 7, 10]
[6, 7, 4, 5, 8, 1, 4, 7, 9, 10]
[6, 4, 5, 7, 1, 4, 7, 8, 9, 10]
[4, 5, 6, 1, 4, 7, 7, 8, 9, 10]
[4, 5, 1, 4, 6, 7, 7, 8, 9, 10]
[4, 1, 4, 5, 6, 7, 7, 8, 9, 10]
[1, 4, 4, 5, 6, 7, 7, 8, 9, 10]
[1, 4, 4, 5, 6, 7, 7, 8, 9, 10]
[1, 4, 4, 5, 6, 7, 7, 8, 9, 10]
"""
To make things complete, here is a selection sort:
# follow the progression of a selection sort
def selection_sort(list1):
for i in range(0, len (list1)):
min = i
for j in range(i + 1, len(list1)):
if list1[j] < list1[min]:
min = j
# do a tuple swap
list1[i], list1[min] = list1[min], list1[i]
print list1
list1 = [8, 10, 6, 7, 4, 5, 9, 1, 4, 7]
selection_sort(list1)
"""
output --->
[1, 10, 6, 7, 4, 5, 9, 8, 4, 7]
[1, 4, 6, 7, 10, 5, 9, 8, 4, 7]
[1, 4, 4, 7, 10, 5, 9, 8, 6, 7]
[1, 4, 4, 5, 10, 7, 9, 8, 6, 7]
[1, 4, 4, 5, 6, 7, 9, 8, 10, 7]
[1, 4, 4, 5, 6, 7, 9, 8, 10, 7]
[1, 4, 4, 5, 6, 7, 7, 8, 10, 9]
[1, 4, 4, 5, 6, 7, 7, 8, 10, 9]
[1, 4, 4, 5, 6, 7, 7, 8, 9, 10]
[1, 4, 4, 5, 6, 7, 7, 8, 9, 10]
"""
The insertion sort is also interesting:
# follow the progression of an insertion sort
def insertion_sort(list1):
for i in range(1, len(list1)):
save = list1[i]
j = i
while j > 0 and list1[j - 1] > save:
list1[j] = list1[j - 1]
j -= 1
list1[j] = save
print list1
list1 = [8, 10, 6, 7, 4, 5, 9, 1, 4, 7]
insertion_sort(list1)
"""
output --->
[8, 10, 6, 7, 4, 5, 9, 1, 4, 7]
[6, 8, 10, 7, 4, 5, 9, 1, 4, 7]
[6, 7, 8, 10, 4, 5, 9, 1, 4, 7]
[4, 6, 7, 8, 10, 5, 9, 1, 4, 7]
[4, 5, 6, 7, 8, 10, 9, 1, 4, 7]
[4, 5, 6, 7, 8, 9, 10, 1, 4, 7]
[1, 4, 5, 6, 7, 8, 9, 10, 4, 7]
[1, 4, 4, 5, 6, 7, 8, 9, 10, 7]
[1, 4, 4, 5, 6, 7, 7, 8, 9, 10]
"""
Under normal circumstances, the insertion and the selection sort are at least twice as fast as the bubble sort.
This might be the simplest way to display an image from a file using the wxPython GUI toolkit:
# simplest way to show an image from a file with wxPython
import wx
app = wx.App(0)
frame = wx.Frame(None, -1, "Show an image file")
# pick an image file you have in the working folder
# (can be a .jpg, .png, ,gif, .bmp image file)
image_file = 'clouds.jpg'
# create an internal image
image = wx.Bitmap(image_file)
# show the image as static bitmap
wx.StaticBitmap(frame, -1, image)
frame.Show()
app.MainLoop()
What the heck, lets make it even simpler:
import wx
app = wx.App(0)
frame = wx.Frame(None, -1, "Show an image file")
wx.StaticBitmap(frame, -1, wx.Bitmap('clouds.jpg'))
frame.Show()
app.MainLoop()
Some heavier wxPython stuff. I was playing around with the wx.ListCtrl() widget, and it took me quite a while to find a way to get a hold of the selected row. Here is a short example of the solution:
# exploring wxPython's
# wx.ListCtrl(parent, id, pos, size, style)
# a fancier list box with a lot of mix-in options
# some of the styles =
# wxLC_REPORT report mode
# wxLC_HRULES draws horizontal rules between rows in report mode
# wxLC_VRULES draws vertical rules between columns in report mode.
import wx
class MyFrame(wx.Frame):
def __init__(self, parent, data):
# use default size and position
wx.Frame.__init__(self, parent, wx.ID_ANY,
'Test the wx.ListCtrl()',
size=(400, 220))
self.SetBackgroundColour("yellow")
# make data available to the instance
self.data = data
# create the list control
self.lc = wx.ListCtrl(self, wx.ID_ANY, size=(-1, 120),
style=wx.LC_REPORT|wx.SUNKEN_BORDER|wx.LC_HRULES)
# select an item (left mouse click on it) and bind to an action
self.lc.Bind(wx.EVT_LIST_ITEM_SELECTED,self.onAction)
self.loadList()
# create an output widget
self.label = wx.StaticText(self, wx.ID_ANY, "Select a name")
# use a vertical boxsizer for the widget placement
sizer_v = wx.BoxSizer(wx.VERTICAL)
sizer_v.Add(self.lc, 1, flag=wx.ALL|wx.EXPAND, border=10)
sizer_v.Add(self.label, 0, flag=wx.ALL|wx.EXPAND, border=10)
self.SetSizer(sizer_v)
def loadList(self):
# first the columns with header titles
self.lc.InsertColumn(0,"Name")
self.lc.SetColumnWidth(0, 200)
self.lc.InsertColumn(1,"Age",wx.LIST_FORMAT_RIGHT)
self.lc.InsertColumn(2,"Weight",wx.LIST_FORMAT_RIGHT)
# now each data row
for key, val in self.data.items():
# set max_rows, change if need be
max_rows = 1000
# also sets/updates row index starting at 0
index = self.lc.InsertStringItem(max_rows, val[0])
self.lc.SetStringItem(index, 1, val[1])
self.lc.SetStringItem(index, 2, val[2])
# needed by GetItemData()
self.lc.SetItemData(index, key)
def onAction(self, event):
""" some action code"""
# …
Once again, what modules does your application import? Some of these modules may not be part of the normal installation and need to be updated too.
Look in "Starting wxPython (GUI code)" right on this forum, for instance:
http://www.daniweb.com/forums/post624835-12.html
Maybe something like this:
def bubbleSort(list1):
swap = False
for j in range(len(list1)-1):
for k in range(len(list1)-1-j):
if list1[k] > list1[k+1]:
list1[k], list1[k+1] = list1[k+1], list1[k]
swap = True
if swap == False:
break
list1 = [4, 6, 2, 8, 1]
bubbleSort(list1)
print list1 # [1, 2, 4, 6, 8]
Alexander Graham Bell was awarded the first U.S. patent for the invention of the telephone in 1876, but Italian Antonio Meucci was recognized by US Congress in 2002 as the true inventor.
A grilled spinach, fontina, roasted garlic, chicken bratwurst on a multigrain demi-baguette and a bottle of cool Sapient Belgian style tripple ale. Heaven on Earth!
Some light wxPython stuff. The first example shows you how to bring in your own icon in the title of a frame:
# set the icon of a wx.Frame()
import wx
app = wx.App(0)
frame = wx.Frame(None, wx.ID_ANY, title='Set A New Icon')
# pick an icon image file you have ...
frame.SetIcon(wx.Icon('py.ico', wx.BITMAP_TYPE_ICO))
frame.Center()
frame.Show()
app.MainLoop()
The second example uses the wx.EVT_SIZE event to respond to changes in the size of the frame:
# use the wx.EVT_SIZE event to show the frame size
# the title itself may take up 34 pixels of the height
import wx
class MyFrame(wx.Frame):
def __init__(self, parent):
# use default size and position
wx.Frame.__init__(self, parent, wx.ID_ANY)
self.SetBackgroundColour("yellow")
wx.StaticText(self, wx.ID_ANY, "change the size of the frame", (5,5))
# respond to changes in the size of the frame
self.Bind(wx.EVT_SIZE, self.onSize)
def onSize(self, event):
"""display the current frame size in the title"""
self.SetTitle(str(event.GetSize())) # eg. (400, 489)
app = wx.App(0)
# create a MyFrame instance and show the frame
MyFrame(None).Show()
app.MainLoop()
Are you talking about Bush or McCain?
In either case a string of pseudo-random phrases would make more sense!
All wars are wars among thieves who are too cowardly to fight and therefore induce the young people of the world to do the fighting for them.
-- Emma Goldman
If someone with multiple personalities robs a bank who is charged with the crime?
God is a comedian playing to an audience too afraid to laugh.
Hmm, you are not too far off GrimJack, here is the solution to our energy crisis from our fearless leader George W. Bush:
"Natural gas is hemispheric. I like to call it hemispheric in nature because it is a product that we can find in our neighborhoods."
What is your exact errror message?
There are some dangling lines in your code like:
Link_Name,Link_Model,Router_A,Router_B,Data_Rate,Direction,COIN=fields
or
CELL_NAME, SWITCH, SWITCH_NAME, LONG, LAT, COINS=fields
Are those comments? If yes, they need a # in front.
Nice observation! Trap the error with try/except like this:
def my_func(aaa, main_var=None):
try:
mvar = [key for key, val in main_var.items() if val==aaa][0]
print aaa, main_var, mvar
except:
print aaa
# other code follows
pass
def main():
test_var = 123
my_func(test_var, vars())
my_func(123, vars())
my_func(456, vars())
my_func(123)
main()
"""
my output -->
123 {'test_var': 123} test_var
123 {'test_var': 123} test_var
456
123
"""
Women need a reason to have sex. Men just need a place.
There are plenty of good jobs around the LA area, somebody has to take care of all the damaged hero veterans.