0

I'm creating a Tkinter-based GUI in Python. I want to let the user interact with the application with hotkeys. I have tried to use this code:

from tkinter import *


def select_all(_event=None):
    print("selected")

root = Tk()
root.bind("<Control-A>", select_all)
root.bind("<Control-a>", select_all)
root.mainloop()

But, unfortunately, it doesn't work when non-english layouts are used.

How can I force Tkinter to run callback on "Control+A" keypress for every language layout?

Demian Wolf
  • 1,698
  • 2
  • 14
  • 34
  • Does this answer your question? [Tkinter international bind](https://stackoverflow.com/questions/14455625/tkinter-international-bind) – Demian Wolf Dec 12 '19 at 16:53

1 Answers1

0

You need to do something like this to use hotkeys with any language layout (the callback from this example is running when Control key is pressed, and prints the key that is pressed in the same time with Control:

from tkinter import *


def callback(event):
    if (event.state & 4 > 0):
        print("Ctrl-%s pressed" % chr(event.keycode))

root = Tk()
root.bind("<Key>", callback)
root.mainloop()

PS: This example was checked when English, Russian, Ukrainian, Arabic, Amharic, Armenian, Greek, Georgian, French, Chinese, Japanese and other language layouts.

Demian Wolf
  • 1,698
  • 2
  • 14
  • 34