Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
936 views
in Technique[技术] by (71.8m points)

python - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...