Search code examples
pythontkinterkeyevent

How to bind key "<" in tkinter?


My code:

from tkinter import *
import tkinter as tk

root = Tk()

def Hello():
    print("You press '<' key")

root.bind("<", Hello)
root.mainloop()

But I receive error:

_tkinter.TclError: no event type or button # or keysym

I tried "<<>" and "Shift-," but it does not work.


Solution

  • What you're looking for is this:

    root.bind("<less>", Hello)
    

    You can find a compete list of Key-Synonyms in the original documentation of Tk.