Question

In Python, is there a way to bind every event generated by an object (perhaps a tkinter widget) to a single function, without explicitly naming them? The motivation here is for learning, debugging and development purposes.

(This question has arisen whilst trying to find a solution to this.)

Était-ce utile?

La solution

You can bind to all of the keys like this:

def callback(event):
    print(event.char, event.keysym, event.keycode)

root = Tk()
root.bind('<Key>', callback)
root.mainloop()
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top