How to get Tkinter Mac-friendly menu shortcuts (cmd+key)

ぃ、小莉子 提交于 2019-11-28 08:16:48

问题


I am considering shortcuts for Tkinter menu labels (commands). On Macs the combination with cmd ⌘ is common.

So far I have found only self.bind_all("<Control-q>", self.quit). How to implement cmd ⌘ shortcuts?

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?


回答1:


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.

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.

Lastly, Python is open-source, so you can always try reading that.

Update: From the code in this answer it sounds like the Command- would work.



来源:https://stackoverflow.com/questions/16379877/how-to-get-tkinter-mac-friendly-menu-shortcuts-cmdkey

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!