Display all attributes of an event : Event « Tkinker « Python Tutorial






Display all attributes of an event
from Tkinter import *
     
def showPosEvent(event):
    print 'Widget=%s X=%s Y=%s' % (event.widget, event.x, event.y)
     
def showAllEvent(event):
    print event
    for attr in dir(event): 
        print attr, '=>', getattr(event, attr) 
     
     
def onMiddleClick(event):
    print 'Got middle mouse button click:', 
    showPosEvent(event)
    showAllEvent(event)
     
tkroot = Tk()
labelfont = ('courier', 20, 'bold')                
widget = Label(tkroot, text='Hello bind world')
widget.config(bg='red', font=labelfont)            
widget.config(height=5, width=20)                  
widget.pack(expand=YES, fill=BOTH)

widget.bind('<Button-2>',  onMiddleClick)          

widget.focus()                                     
tkroot.title('Click Me')
tkroot.mainloop()








18.12.Event
18.12.1.Display all attributes of an eventDisplay all attributes of an event
18.12.2.Print a description of an event, based on its attributesPrint a description of an event, based on its attributes
18.12.3.Variable length parameters for event methodVariable length parameters for event method
18.12.4.Demonstrates binding an event with an event handlerDemonstrates binding an event with an event handler
18.12.5.Call sys.exit command from ButtonCall sys.exit command from Button
18.12.6.Call root.quit from buttonCall root.quit from button