Home > database >  Is there a way to bind delete button on Mac to a lambda function in python Tkinter?
Is there a way to bind delete button on Mac to a lambda function in python Tkinter?

Time:01-21

I'm trying to bind the delete keyboard button on Mac with a lambda function in python Tkinter.

I don't know the name for the delete button. Please help, thank you in advance.

CodePudding user response:

import tkinter as tk

root = tk.Tk()

e = tk.Entry( root )
e.grid()

def on_key(event ):
    print( event.keysym )

e.bind( '<Delete>', on_key )
e.bind( '<KP_Delete>', on_key )
# Key Pad delete isn't on any of my keyboards

e.bind( '<BackSpace>', on_key )

#  --- OR Un comment to explore other key names. ---
# e.bind( '<Key>', on_key )

root.mainloop()
  • Related