Skip to content Skip to sidebar Skip to footer

Tkinter Determine Keyboard Layout

Is there a way to detect current keyboard layout in Tkinter? It is necessary to process keyboard accelerators correctly for such languages as Russian, French, Greek (see my other q

Solution 1:

No, there is no such feature built into Tkinter.

Why not simply have your application ask the user where each special key is, the first time the app starts up? Apple does this with OSX -- it asked me to press a couple of keys the very first time I booted up a fresh install.

You can put the focus into a widget and bind to <Any-KeyPress>, and from that grab enough information to bind to whatever key they pressed.

Solution 2:

Seems that keysym is "??" if layout is not english.

defkey_callback(e):
    # Generate Ctrl-V if current layout is not englishif e.state & 4 > 0andchr(e.keycode) == 'V'and e.keysym == "??":
        root.focus_get().event_generate("<<Paste>>")
root.bind("<Key>", key_callback)

Post a Comment for "Tkinter Determine Keyboard Layout"