Mega Code Archive

 
Categories / Python Tutorial / Tkinker
 

Wrap action command in a class

from Tkinter  import *       class HelloCallable:     def __init__(self):                               self.msg = 'Hello __call__ world'      def __call__(self):         print self.msg                                import sys; sys.exit()                      widget = Button(None, text='event', command=HelloCallable()) widget.pack() widget.mainloop()