Tkinter __call__
John McMonagle
jmcmonagle at velseis.com.au
Thu Feb 15 20:25:40 EST 2007
Gigs_ wrote:
> 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?
Add the following lines to the end of your script and all should work as
expected:
root = Tk()
app = Demo(root)
root.mainloop()
More information about the Python-list
mailing list