问题描述
在使用NumPad在Windows和Linux之间切换时,我在tkinter中遇到有关KeyPress绑定的问题。在Windows上可以使用self.bind("-",function)
,但在Linux上不会触发。
通过下面的代码片段,我发现键盘减号的事件与数字键盘减号的事件不同。
代码:
import tkinter as tk
class App(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
self.bind("<Key>",self.action)
self.count = 0
def action(self,e):
print(e)
self.count += 1
app = App()
app.mainloop()
输出:
NumPad:
<KeyPress event state=Mod2 keysym=KP_Subtract keycode=82 char=‘-‘ x=323 y=-184
KeyBoard:
<KeyPress event state=Mod2 Keysym=minus keycode=61 char=’-‘ x=376 y=-27
是否有一种方法可以使Linux识别tkinter绑定中的“-”字符(无论是键盘还是NumPad)?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)