首页 > 文章列表 > python中TKinter的绑定方法

python中TKinter的绑定方法

Python TKinter
499 2022-08-07

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

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

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

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

实例

from Tkinter import *
 
root = Tk()
def callback(event):
    print "clicked at", event.x, event.y
frame = Frame(root, width=100, height=100)
frame.bind("<Button-1>", callback)
frame.pack()
 
root.mainloop()

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