2010-09-09 66 views

回答

5

該事件有一個小部件領域,可以幫助您區分哪些部件是源:

from Tkinter import * 

class MyObj: 
    def callback(self, event): 
     print event.widget.message 

obj = MyObj() 
root = Tk() 
btn=Button(root, text="Click") 
btn.bind('<Button-1>', obj.callback) 
btn.pack() 
btn.message = 'Hello' 

btn2=Button(root, text="Click too") 
btn2.bind('<Button-1>', obj.callback) 
btn2.message = 'Salut' 
btn2.pack() 

root.mainloop() 
相關問題