문제

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