Skip to content
Advertisement

Cannot bind NumPad minus key on Linux with Tkinter

I encountered an issue regarding KeyPress binds in tkinter when switching between Windows and Linux while using a NumPad. Using self.bind("-", function) works on Windows, however is not triggered on Linux.

With the following code snippet I found out that the events of a keyboard-minus differs from a numpad-minus.

Code:

JavaScript

Output:

JavaScript

Is there a way to make Linux recognize the “-” char in a tkinter bind whether it is from keyboard or NumPad?

Advertisement

Answer

Is there a way to make Linux recognize the “-” char from both the keyboard and the NumPad in a tkinter bind?

I have wrote code where you can choose from the OptionMenu from the options you have:

You could bind both keysyms to the same function. – jasonharper

keep binding to any key and dispatch based on the char attribute of the event. – Sven Marnach

use both the upper methods.

Running the provided code you can see that binding to both, ‘any key’ and the ‘minus’ key suppresses the key event for pressing ‘any key’ to be triggered in case the ‘minus’ key is pressed:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement