What Events Does 'Command' Bind To? : Event « GUI Tk « Python






What Events Does 'Command' Bind To?

What Events Does 'Command' Bind To?
 

from Tkinter import *

class MyApp:
  def __init__(self, parent):
    self.myParent = parent   
    self.myContainer1 = Frame(parent)
    self.myContainer1.pack()
    
    self.button1 = Button(self.myContainer1, command=self.button1Click)  
    self.button1.bind("<Return>", self.button1Click_a)    
    self.button1.configure(text="OK")
    self.button1.pack(side=LEFT)
    self.button1.focus_force()       
    
    self.button2 = Button(self.myContainer1, command=self.button2Click)   
    self.button2.bind("<Return>", self.button2Click_a)    
    self.button2.configure(text="Cancel")     
    self.button2.pack(side=RIGHT)
    
  def button1Click(self):  
    print "button1Click event handler" 
    if self.button1["background"] == "green":  
      self.button1["background"] = "yellow"
    else:
      self.button1["background"] = "green"
  
  def button2Click(self): 
    print "button2Click event handler" 
    self.myParent.destroy()      
  
  def button1Click_a(self, event):  
    print "button 1 Click event" 
    self.button1Click()
        
  def button2Click_a(self, event):  
    print "button 2 Click event" 
    self.button2Click()
        
              
root = Tk()
myapp = MyApp(root)
root.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.adds callbacks function to a buttonadds callbacks function to a button
5.Add system exit action to a buttonAdd system exit action to a button
6.Update Label in action event
7.Class wrapper for GUI
8.Use lambda to generate a call back function for a buttonUse lambda to generate a call back function for a button