鼠標與鍵盤事件
1 import tkinter 2 3 wuya = tkinter.Tk() 4 wuya.title("wuya") 5 wuya.geometry("300x200+10+20") 6 7 8 9 bt = tkinter.Button(wuya,text='鼠標進入打印') 10 bt.pack() 11 12 def func(event): 13 print('鼠標進入按鈕') 14 # 綁定事件,鼠標進入按鈕的時候執行func()函數,在控制台打印:鼠標進入按鈕 15 bt.bind('<Enter>',func) 16 17 18 # 還有其他的事件 19 # 只需改變bind中的第一個參數,用以下對應的字符串替換即可 20 ''' 21 <Button-1> 鼠標左鍵按下,2表示中鍵,3表示右鍵; 22 <ButtonPress-1> 同上; 23 <ButtonRelease-1> 鼠標左鍵釋放; 24 <B1-Motion> 按住鼠標左鍵移動; 25 <Double-Button-1> 雙擊左鍵; 26 <Enter> 鼠標指針進入某一組件區域; 27 <Leave> 鼠標指針離開某一組件區域; 28 <MouseWheel> 滾動滾輪; 29 <KeyPress-A> 按下A鍵,A可用其他鍵替代; 30 <Alt-KeyPress-A> 同時按下alt和A;alt可用ctrl和shift替代; 31 <Double-KeyPress-A> 快速按兩下A; 32 <Lock-KeyPress-A> 大寫狀態下按A; 33 34 ''' 35 36 37 wuya.mainloop()
還有一些其他的事件,用法類似,查看筆者的tkinter中的總結:http://www.cnblogs.com/wuyazi/p/8779319.html