newbie here.
I'm using tkinter for this.
In below code label text immediately updates when key 1, 2 or 3 is pressed. When another regular key (like 'k' or '5') is pressed before, it also immediately updates.
But, now the problem: when a special key (like Alt) is pressed before, it only updates when first any key is pressed, and then 1, 2 or 3. Like you need to press twice after a special key is pressed.
In code below try/except is used to ignore ValueError of special key input.
What I want is that the label text always immediately updates no matter what key is pressed before.
Please share how to do this, thanks!
from tkinter import *
def getKey(event):
userIn=''
try:
if event.char in '1 2 3':
userIn = event.char
l['text'] = userIn
except:
pass
root = Tk()
l = Label(root, text='input')
l.pack()
root.bind('<Key>', getKey)
root.mainloop()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…