連接鍵盤事件
from tkinter import*
root = Tk()
def callback(event):
print(event.char)
frame =Frame(root,width=200,height=200)
frame.bind("<Key>",callback)
frame.focus_set()
frame.pack()
mainloop()
通過鍵盤輸入就可以獲取輸入信息
Motion:實時獲取鼠標位置
from tkinter import*
root = Tk()
def callback(event):
print("當前位置:",event.x,event.y)
frame =Frame(root,width=200,height=200)
frame.bind("<Motion>",callback)
frame.focus_set()
frame.pack()
mainloop()
正片開始
使用以下keysym
from tkinter import*
root = Tk()
def callback(event):
print(event.keysym)
frame =Frame(root,width=200,height=200)
frame.bind("<Key>",callback)
frame.focus_set()
frame.pack()
mainloop()
這樣就會出現鍵盤輸入的東西