【发布时间】:2021-03-03 21:56:53
【问题描述】:
我创建了一个具有 4 个功能的 tkinter 应用程序。其中 2 个函数是上传文件的函数,另外 2 个函数是修改这些文件的函数。我想使用“线程”库,因为 tkinter 在修改函数运行时会一直冻结。
当我运行下面更改的代码时,所有函数同时运行。
例如,我什至没有点击“上传”按钮,tkitner 应用程序提示我上传文件,这两个功能。怎样才能让它只有在我点击按钮时才能运行?
btni = Button(
root, text="Upload File",width=16, command=threading.Thread(target =open_inv_file).start(), background="blue4", foreground="white"
)
btni.place(x=185, y=220)
btnm = Button(
root, text="Run", width=16,command=threading.Thread(target =main).start(), background="blue4", foreground="white"
)
btnm.pack()
btnm.place(x=185, y=250)
btn = Button(
root, text="Upload File",width=16, command=threading.Thread(target =open_file).start(), background="blue4", foreground="white"
)
btn.place(x=185, y=105)
btn3 = Button(
root, text="Run", command=threading.Thread(target =run).start(), width=16, background="blue4", foreground="white"
)
btn3.place(x=185, y=137)
【问题讨论】:
标签: python multithreading tkinter