python中TKinter的绑定方法

Python (191) 2023-05-27 15:35:59

1、bind_all全局绑定,默认是全局快捷键,比如F1是帮助文档。

2、bind_class接受三个参数,第一个是类名,第二个是事件,第三个是操作。

3、bind单独绑定某个实例。

4、unbind解绑需要一个参数,即想解绑哪个事件。

实例

纯文本
复制到剪贴板
在新窗口中打开代码
EnlighterJS 3 Syntax Highlighter
fromTkinterimport*
root=Tk()
defcallback(event):
print"clickedat",event.x,event.y
frame=Frame(root,width=100,height=100)
frame.bind("<Button-1>",callback)
frame.pack()
root.mainloop()
fromTkinterimport* root=Tk() defcallback(event): print"clickedat",event.x,event.y frame=Frame(root,width=100,height=100) frame.bind("<Button-1>",callback) frame.pack() root.mainloop()
fromTkinterimport*

root=Tk()
defcallback(event):
print"clickedat",event.x,event.y
frame=Frame(root,width=100,height=100)
frame.bind("<Button-1>",callback)
frame.pack()

root.mainloop()

以上就是python中TKinter的绑定方法,希望对大家有所帮助。

(推荐操作系统:windows7系统、Python 3.9.1,DELL G3电脑。)

THE END

发表回复