KaiXtr
KaiXtr

Reputation: 23

Bind '<' key in Tkinter

It's a simple question, there is a way to take the ASCII code of a character to bind or anything else? I searched for aswners before making the question

Upvotes: 1

Views: 155

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 385960

To bind to < you need to bind to the event <less>.

A handy trick to know what to bind to for some of the more unusual keys is to write a program that displays the keysym of every key you press. For example:

import tkinter as tk
root = tk.Tk()
label = tk.Label(root, width=20, height=2, font=("Helvetica", 24))
label.pack(fill="both", padx=10, pady=10)
root.bind("<Any-KeyPress>",
          lambda event: label.configure(text=event.keysym))
root.focus_set()
root.mainloop()

Upvotes: 1

Related Questions