tkinter绑定多个事件
tkinter怎么为一个组件绑定多个事件? import tkinter as tkclass Application(tk.Frame):
def __init__(self,master=None):
super().__init__(master)
self.master = master
self.root = root
self.createWidget()
def createWidget(self): # 创建组件
self.btn_1 = tk.Button(self.root,text="测试")
self.btn_1.pack()
# 绑定事件
self.btn_1.bind('<Button-1>',self.btn_1_left)
self.btn_1.bind('<Double-Button-1>',self.btn_1_double_left)
self.btn_1.bind('<Button-3>',self.btn_1_right)
self.btn_1.bind('<Double-Button-3>',self.btn_1_double_right)
def btn_1_left(self,event):
print('被鼠标左键单击')
def btn_1_double_left(self,event):
print('被鼠标左键双击')
def btn_1_right(self,event):
print('被鼠标右键单击')
def btn_1_double_right(self,event):
print('被鼠标右键双击')
if __name__ == '__main__':
root = tk.Tk()
root.geometry("300x200")
app = Application(root)
root.mainloop()
页:
[1]