Use lambda to generate a call back function for a button : Event « GUI Tk « Python






Use lambda to generate a call back function for a button

Use lambda to generate a call back function for a button
 

from Tkinter import *
from sys import stdout, exit      

widget = Button(None,             
             text='Hello event world', 
             command=(lambda: stdout.write('Hello lambda world\n') or exit()) )
widget.pack()
widget.mainloop()


           
         
  








Related examples in the same category

1.Binding an event with an event handlerBinding an event with an event handler
2.Associating arguments to an event-handler functionAssociating arguments to an event-handler function
3.Sharing Information Between Event-Handler FunctionsSharing Information Between Event-Handler Functions
4.What Events Does 'Command' Bind To?What Events Does 'Command' Bind To?
5.adds callbacks function to a buttonadds callbacks function to a button
6.Add system exit action to a buttonAdd system exit action to a button
7.Update Label in action event
8.Class wrapper for GUI