python 监听键盘事件
#coding=utf-8 from tkinter import * root=Tk() def callback(event): print("点击键盘",repr(event.char)) frame=Frame(root,width=200,height=200) frame.bind("<Key>",callback) frame.focus_set() frame.pack() mainloop()
效果图:
#coding=utf-8 from tkinter import * root=Tk() def callback(event): print("点击键盘",repr(event.char)) frame=Frame(root,width=200,height=200) frame.bind("<Key>",callback) frame.focus_set() frame.pack() mainloop()
效果图: