且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

检测 Python 中的按键输入

更新时间:2022-06-24 09:57:05

你可以制作一个小 Tkinter 应用程序:

You could make a little Tkinter app:

import Tkinter as tk

def onKeyPress(event):
    text.insert('end', 'You pressed %s
' % (event.char, ))

root = tk.Tk()
root.geometry('300x200')
text = tk.Text(root, background='black', foreground='white', font=('Comic Sans MS', 12))
text.pack()
root.bind('<KeyPress>', onKeyPress)
root.mainloop()