bing
程序退出root.protocol('WM_DELETE_WINDOW', printProtocol)
import tkinter as tk
root = tk.Tk()
###################################
# 鼠标事件
###################################
def printroot(event):
print(event.x,event.y)
bt = tk.Button(root, text=":双击事件 ")
bt1 = tk.Button(root, text=":三击事件 ")
bt2 = tk.Button(root, text=":鼠标离开时产生此事件")
bt3 = tk.Button(root, text=":鼠标左击事件")
bt4 = tk.Button(root, text=":鼠标右击事件")
bt5 = tk.Button(root, text=":鼠标中击事件")
bt6 = tk.Button(root, text=":鼠标移动事件,x=[1,2,3]分别表示左、右、中鼠标操作。 ")
bt7 = tk.Button(root, text="鼠标释放事件,x=[1,2,3],分别表示鼠标的左、右、中键操作 ")
bt.grid()
bt1.grid()
bt2.grid()
bt3.grid()
bt4.grid()
bt5.grid()
bt6.grid()
bt7.grid()
bt.bind("",printroot)
bt1.bind("",printroot)
bt2.bind("",printroot)
bt3.bind("",printroot)
bt4.bind("",printroot)
bt5.bind("",printroot)
bt6.bind("",printroot)
bt7.bind("",printroot)
###################################
# 键盘事件
###################################
def printkey(event):
print("event.char = " + event.char)
print('event.keycode = ', event.keycode)
root.bind("",printkey)
root.bind("",printkey)
root.bind("",printkey)
root.bind("",printkey)
###################################
# 程序退出
###################################
def printProtocol():
print('WM_DELETE_WINDOW')
root.destroy()
root.protocol('WM_DELETE_WINDOW', printProtocol)
root.mainloop()