国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術(shù)文章
文章詳情頁

Python tkinter之Bind(綁定事件)的使用示例

瀏覽:132日期:2022-06-28 11:29:50
1、綁定鼠標(biāo)事件并獲取事件屬性

# -*- encoding=utf-8 -*-import tkinterfrom tkinter import *def left_mouse_down(event): print(’鼠標(biāo)左鍵按下’) # 事件的屬性 widget = event.widget print(’觸發(fā)事件的組件:{}’.format(widget)) print(’組件顏色:{}’.format(widget.cget(’bg’))) widget_x = event.x # 相對于組件的橫坐標(biāo)x print(’相對于組件的橫坐標(biāo):{}’.format(widget_x)) widget_y = event.y # 相對于組件的縱坐標(biāo)y print(’相對于組件的縱坐標(biāo):{}’.format(widget_y)) x_root = event.x_root # 相對于屏幕的左上角的橫坐標(biāo) print(’相對于屏幕的左上角的橫坐標(biāo):{}’.format(x_root)) y_root = event.y_root # 相對于屏幕的左上角的縱坐標(biāo) print(’相對于屏幕的左上角的縱坐標(biāo):{}’.format(y_root))def left_mouse_up(event): print(’鼠標(biāo)左鍵釋放’)def moving_mouse(event): print(’鼠標(biāo)左鍵按下并移動’)def moving_into(event): print(’鼠標(biāo)進(jìn)入’)def moving_out(event): print(’鼠標(biāo)移出’)def right_mouse_down(event): print(’鼠標(biāo)右鍵按下’)def right_mouse_up(event): print(’鼠標(biāo)右鍵釋放’)def pulley_up(event): print(’滑輪向上滾動’)def focus(event): print(’聚焦事件’)def unfocus(event): print(’失焦事件’)if __name__ == ’__main__’: win = tkinter.Tk() # 窗口 win.title(’南風(fēng)丶輕語’) # 標(biāo)題 screenwidth = win.winfo_screenwidth() # 屏幕寬度 screenheight = win.winfo_screenheight() # 屏幕高度 width = 500 height = 300 x = int((screenwidth - width) / 2) y = int((screenheight - height) / 2) win.geometry(’{}x{}+{}+{}’.format(width, height, x, y)) # 大小以及位置 label = Label(text=’標(biāo)簽’, relief=’g’, font=(’黑體’, 20)) label.pack(pady=10) label.bind(’<Button-1>’, left_mouse_down) # 鼠標(biāo)左鍵按下 label.bind(’<ButtonRelease-1>’, left_mouse_up) # 鼠標(biāo)左鍵釋放 label.bind(’<Button-3>’, right_mouse_down) # 鼠標(biāo)右鍵按下 label.bind(’<ButtonRelease-3>’, right_mouse_up) # 鼠標(biāo)右鍵釋放 label.bind(’<B1-Motion>’, moving_mouse) # 鼠標(biāo)左鍵按下并移動 label.bind(’<Enter>’, moving_into) # 鼠標(biāo)移入事件 label.bind(’<Leave>’, moving_out) # 鼠標(biāo)移出事件 label.bind(’<FocusIn>’, focus) # 聚焦事件 label.bind(’<FocusOut>’, unfocus) # 失焦事件 label.focus_set() # 直接聚焦 Entry().pack() win.mainloop()

Python tkinter之Bind(綁定事件)的使用示例

2、綁定鍵盤事件并獲取事件屬性

# -*- encoding=utf-8 -*-import tkinterfrom tkinter import *def keyboard_event(event): char = event.char print(’回車 char:{}’.format(char)) key_code = event.keycode print(’回車 key code:{}’.format(key_code))def entry_enter(event): print(’輸入的內(nèi)容為:’ + entry.get())def shift_f(event): print(’SHIFT + F’) print(event.char) print(event.keycode)def num_lock(event): print(’num_lock’) print(event.char) print(event.keycode)if __name__ == ’__main__’: win = tkinter.Tk() # 窗口 win.title(’南風(fēng)丶輕語’) # 標(biāo)題 screenwidth = win.winfo_screenwidth() # 屏幕寬度 screenheight = win.winfo_screenheight() # 屏幕高度 width = 500 height = 300 x = int((screenwidth - width) / 2) y = int((screenheight - height) / 2) win.geometry(’{}x{}+{}+{}’.format(width, height, x, y)) # 大小以及位置 label = Label(text=’標(biāo)簽’, relief=’g’, font=(’黑體’, 20)) label.pack(pady=10) label.focus_set() label.bind(’<Return>’, keyboard_event) # 按下回車 label.bind(’<Shift F>’, shift_f) label.bind(’<Num_Lock>’, num_lock) entry = Entry() entry.pack() entry.bind(’<Return>’, entry_enter) # 按下回車 win.mainloop()

Python tkinter之Bind(綁定事件)的使用示例

以上就是Python tkinter之Bind(綁定事件)的使用示例的詳細(xì)內(nèi)容,更多關(guān)于python tkinter Bind(綁定事件)的資料請關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 亚洲福利影视 | 欧美怡红院在线 | aa毛片免费全部播放完整 | 久久色视频在线观看 | 欧美日韩一区二区三区高清不卡 | 亚洲综合国产精品 | 网友自拍第一页 | 国产成人精视频在线观看免费 | 国产美女一级特黄毛片 | 亚洲毛片免费观看 | 亚洲国产成人久久一区www | 国产精品一区二区综合 | 欧美成人免费高清网站 | 波多野结衣一级片 | 国产亚洲精品2021自在线 | 国产精品区在线12p 国产精品人成 | 欧美深夜影院 | 99在线在线视频免费视频观看 | 美女张开腿让男人 | 亚洲码在线观看 | 九九国产在线 | 国内自拍视频在线看免费观看 | 一区二区三区四区国产精品 | 99在线精品免费视频九九视 | 亚洲毛片免费视频 | 九九九免费视频 | 日韩一级视频在线观看播放 | 玖玖玖视频在线观看视频6 玖玖影院在线观看 | 中文字幕亚洲一区二区v@在线 | 亚洲精品国产一区二区在线 | 成人一级片在线观看 | 国产精品变态重口在线 | 亚洲一区二区精品推荐 | 国产呦系列免费 | 欧美一二三区在线 | 久草中文在线 | 日韩欧美国产另类 | 亚州毛片| 国产午夜精品免费一二区 | 一本本久综合久久爱 | 免费精品国产日韩热久久 |