Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 200
solarisman Avatar asked Oct 04 '22 05:10

solarisman


1 Answers

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.

like image 178
martineau Avatar answered Oct 10 '22 03:10

martineau