本文介紹了檢測 Python 中的鍵輸入的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
(2013 年) 不知道為什么 Python 這么奇怪,google 搜不到這個,但是很簡單.
(In 2013) I don't know why Python is that weird, you can't find this by searching in google very easily, but it's quite simple.
如何檢測SPACE"或任何鍵?我該怎么做:
How can I detect 'SPACE' or actually any key? How can I do this:
print('You pressed %s' % key)
這應該包含在python核心中,所以請不要鏈接與核心python無關的模塊.
This should be included in python core, so please do not link modules not related for core python.
推薦答案
你可以做一個小 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()
這篇關于檢測 Python 中的鍵輸入的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!