[Python] Tkinter how to distinguish between <Key> and <Control-Key> bindings?

Discussão em 'Python' iniciado por Stack, Janeiro 27, 2025.

  1. Stack

    Stack Membro Participativo

    This might be a simple answer.

    I have a text widget which i want to bind any alphanumeric keyboard key (a-zA-Z0-9_ and rest of regular keys) to a specific method, and Ctrl+F to another method.

    Using widget.bind("<Key>", method) will create the following:

    1. Click Ctrl+F will invoke method twice, one for Ctrl (event.keysym = Control_L, event.char = None) and second for F (event.keysym = f, event.char = <invalid>)
    2. Click F will invoke method (event.keysym = f, event.char = f)

    Is there a way to distinguish between the two scenarios?

    Continue reading...

Compartilhe esta Página