我有一个在tkinter
应用程序中作为上下文菜单显示的菜单:
rmenu = tk.Menu(None, tearoff=0, takefocus=0)
# add some commands here
rmenu.add_command(label="Copy", copyfunction, accelerator="Shift-C")
rmenu.bind("<Shift-KeyPress-C>", copyfunction) # this doesn't work on windows!
我在这个上下文菜单中为命令定义了一个快捷方式,然后,当我试图通过在<Shift>
windows上键入<C>
+来运行该命令时,它无法工作。实际上,我听到一声嘟嘟声。
在这种情况下,有没有定义快捷方式的方法?
更新:
我甚至尝试使用以下方法在程序中生成一个事件:
rmenu.event_generate("<Shift-KeyPress-C>", when="tail")
但是函数copyfunction
没有被调用。
PS:这个工作在Linux上。
发布于 2020-08-18 13:18:17
bind
到root
的键盘快捷方式。只有使用focus
的东西才能侦听键绑定。上下文菜单多久有一次有焦点?通过在bind_all
上使用root
,任何有focus
的东西都会触发键绑定。
root.bind_all("<Shift-C>", copyfunction)
https://stackoverflow.com/questions/63475483
复制