是否可以将同一事件的多个事件处理程序绑定到一个小部件? Tkinter
Is it possible to bind multiple event handlers for the same event to a widget? Tkinter
我想将同一个键绑定到同一个小部件,但具有不同的事件,但每当我这样做时,第一个事件就会被忽略。
from tkinter import *
root = Tk()
c = StringVar()
c2 = StringVar()
def myfunction():
c.set('Hello World')
def myfunction2():
c2.set('Hello World, again')
root.bind('<Enter>', lambda event: myfunction()
label = Label(root, textvariable=c, bg='#0f0f0f', fg='white',
font=('@Yu Gothic Light', 12))
label.place(x=4, y=160)
root.bind('<Enter>', lambda event: myfunction2())
label2 = Label(root, textvariable=c2, bg='#0f0f0f', fg='white',
font=('@Yu Gothic Light', 12))
label2.place(x=4, y=190)
# label 2 doesn't show anything and just gets ignored
root.mainloop()
我想做的是在光标触及根部时为特定文本设置标签window。
请帮忙。
bind
的默认行为是替换 现有绑定。
如果要添加它们,需要使用add
参数。
root.bind('<Enter>', lambda event: myfunction2(), add="+")
我想将同一个键绑定到同一个小部件,但具有不同的事件,但每当我这样做时,第一个事件就会被忽略。
from tkinter import *
root = Tk()
c = StringVar()
c2 = StringVar()
def myfunction():
c.set('Hello World')
def myfunction2():
c2.set('Hello World, again')
root.bind('<Enter>', lambda event: myfunction()
label = Label(root, textvariable=c, bg='#0f0f0f', fg='white',
font=('@Yu Gothic Light', 12))
label.place(x=4, y=160)
root.bind('<Enter>', lambda event: myfunction2())
label2 = Label(root, textvariable=c2, bg='#0f0f0f', fg='white',
font=('@Yu Gothic Light', 12))
label2.place(x=4, y=190)
# label 2 doesn't show anything and just gets ignored
root.mainloop()
我想做的是在光标触及根部时为特定文本设置标签window。 请帮忙。
bind
的默认行为是替换 现有绑定。
如果要添加它们,需要使用add
参数。
root.bind('<Enter>', lambda event: myfunction2(), add="+")