Tkinter international bind

前端 未结 5 1403
清酒与你
清酒与你 2020-12-11 17:28

Is there a way in Tkinter to bind a combination of keys that will work in all keyboard layouts? (bind by scancode)

For example, I need \'Control-Z\' bin

5条回答
  •  不知归路
    2020-12-11 18:07

    What I'm primarily interested in is Russian layout in Windows.

    The quick and dirty workaround I currently use is:

    import Tkinter
    
    def copy(event):
        print 'Ctrl-C'
    
    root = Tkinter.Tk()
    root.bind('', copy)
    root.mainloop()
    

    which could potentially lead to a conflict with actual ntilde> in some other language.

    It could be overcome if I could determine which layout is currently active, thus second question: Tkinter determine keyboard layout.

    Another drawback is that due to 'universal' treatment of modifier keys it also fires when I press Ctrl-Alt-V, but that's another story as it applies to English layout as well.

提交回复
热议问题