Tkinter windows key event

Question:

What is the event for the Windows key in Tkinter? I’m using Linux, but I would like answers for both Linux and Windows. If Mac has a similar key, feel free to let me know the binding for it. I imagine there are different events for the left and right windows keys.

The windows key doesn’t seem to register in my program that is supposed to catch all key presses and print what they are to the screen. I haven’t seen an answer in my searches online. I’ve seen references to Mod4 being associated with the Windows key, but that’s not a proper Tkinter event (so says my error):

_tkinter.TclError: bad event type or keysym "Mod4"

E.g. the following code gets the above error.

textWidget.bind("<Mod4>", self.myFunction)
Asked By: Brōtsyorfuzthrāx

||

Answers:

Okay, I found the answer. It was pretty simple, and I don’t know why I couldn’t find it on the Internet, anywhere.

The event is called Super_L (for the left Windows key on Linux). The right Windows key is Super_R. I don’t know if these events work on Windows and Mac, though.

Anyway, the reason my event key-press finder didn’t find it was because I had a script running at my computer start-up that defined the compose key as being the left windows key. So, it didn’t register for some reason.

Answered By: Brōtsyorfuzthrāx

After some digging I found this: https://www.tcl.tk/man/tcl8.6/TkCmd/keysyms.htm
These: <Win_L>, <Win_R>, appear to be the correct keys for Windows. Tested in Python 3.4 on Win7.

Answered By: Von Pittman