我想將同一個鍵系結到同一個小部件但具有不同的事件,但是每當我這樣做時,第一個事件就會被忽略。
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()
我要做的是在游標觸摸根視窗時將標簽設定為特定文本。請幫忙。
uj5u.com熱心網友回復:
的默認行為bind是替換現有系結。
如果要添加它們,則需要使用add引數。
root.bind('<Enter>', lambda event: myfunction2(), add=" ")
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/457950.html
