Вопрос

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.)

Это было полезно?

Решение

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()
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top