Tkinter __call__
Gigs_
gigs at hi.t-com.hr
Thu Feb 15 18:10:21 EST 2007
from Tkinter import *
from tkFileDialog import askopenfilename
from tkColorChooser import askcolor
from tkMessageBox import askquestion, showerror
from tkSimpleDialog import askfloat
demos = {
'Open': askopenfilename,
'Color': askcolor,
'Query': lambda: askquestion('Warning', 'You typed
"..."\nConfirm?'),
'Error': lambda: showerror('Error!', "He's dead, Jim"),
'Input': lambda: askfloat('Entry', 'Enter credit card number')
}
class Demo(Frame):
def __init__(self, parent=None):
Frame.__init__(self, parent)
self.pack()
Label(self, text="Basic demos").pack()
for (key, value) in demos.items():
func = (lambda key=key: self.printit(key))
Button(self, text=key, command=func).pack(side=TOP, fill=BOTH)
def printit(self, name):
print name, 'returns =>', demos[name]()
I have tried but cant get it to work properly.
I want to instead printit method to put __call__ and call it like that
Can someone help me, please?
More information about the Python-list
mailing list