如何获得 Tkinter Mac 友好的菜单快捷方式(cmd+key) [英] How to get Tkinter Mac-friendly menu shortcuts (cmd+key)
问题描述
我正在考虑 Tkinter 菜单标签(命令)的快捷方式.在 Mac 上,与 cmd ⌘ 的组合很常见.
I am considering shortcuts for Tkinter menu labels (commands). On Macs the combination with cmd ⌘ is common.
到目前为止,我只找到了 self.bind_all("
.如何实现 cmd ⌘ 快捷键?
So far I have found only self.bind_all("<Control-q>", self.quit)
. How to implement cmd ⌘ shortcuts?
然后再想一想 - 一旦应用程序完成 - 将其转换为适用于 Windows 和 Mac 应用程序的可执行文件可能会在使用 cmd ⌘ 时造成困难?处理此问题的最佳方法是什么?
Then again, thinking about - once the app is finished - translating it to an executable file for Windows and a Mac application might cause difficulties when using cmd ⌘? What is the best way of dealing with this issue?
推荐答案
我认为您需要指定 Tk 内置命令 -- 也许是 Mod1
而不是 控制代码>.您可能还会发现此 Tk 识别的键符 的列表很有用.
I think you would need to specify one of the Meta and M Modifiers listed at Tk Built-in Commands -- perhaps Mod1
instead of Control
. You might also find this list of keysyms recognized by Tk useful.
虽然我从来没有真正尝试过——如果一切都失败了——你也许可以通过编写自己的事件处理函数来确定你需要知道什么def handlerName(event):
,将其绑定到 '
事件,然后,在函数 print
中传递传递给它的事件参数的属性值当它被调用时——例如 event.keycode
、event.keysym
、event.keysym_num
等——从而让你看到要做什么用于检测 Mac 上的 ⌘ 键修改按键.
Although I've never actually every tried to do it -- if all else fails -- you might be able to determine what you need to know by writing your own event handler function def handlerName(event):
, bind it to '<Any-KeyPress>'
events, and then, in the function print
the values of the attributes of the event argument being passed it when it's called -- such as event.keycode
, event.keysym
, event.keysym_num
, etc -- thereby allowing you to see what to use for detecting ⌘-key modified keystrokes on your Mac.
最后,Python 是开源的,因此您可以随时尝试阅读.
Lastly, Python is open-source, so you can always try reading that.
更新:从这个 answer 中的代码看来,Command-
会起作用.
Update: From the code in this answer it sounds like the Command-
would work.
这篇关于如何获得 Tkinter Mac 友好的菜单快捷方式(cmd+key)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!