[英]My multithread tkinter code only works when I run it on Pycharm, not in an .exe. It opens an unwanted window, even with __name__ == "__main__"
I have multiple files in this project, and, in this particular case, I call a function from another file.我在这个项目中有多个文件,在这种特殊情况下,我从另一个文件中调用 function。
from botmain import Execute
def EXECUTE_BOT(first_line, last_line, filename, padrao_comunicacao, concentrador, varredura, eventos, osci, param, ons,
empresa, grpparam, cnldgt, addparams):
time.sleep(5)
Execute(first_line,
last_line,
filename,
padrao_comunicacao,
concentrador,
varredura,
eventos,
osci,
param,
ons,
empresa,
grpparam,
cnldgt,
addparams)
if __name__ == '__main__':
root = Tk()
root.grab_set()
root.resizable = False
frm = ttk.Frame(root, padding=20)
frm.grid()
ttk.Button(frm, text="EXECUTAR", command=lambda: EXECUTE_BOT(wdg_firstLine.get(),
wdg_lastLine.get(),
wdg_sheetdirectory.cget("text"),
wdg_padrao_comunicacao.get(),
wdg_conc.get(),
radio_var.get(),
radio_eve.get(),
radio_osc.get(),
radio_param.get(),
radio_ons.get(),
wdg_empresa.get(),
wdg_grpParam.get(),
wdg_cnlDgt.get(),
converAddParam(addparam_list))).grid(column=5, row=22)
This code works just fine when I run it on Pycharm, but when I make it a.exe with pyinstaller, it stops working, and it opens another window every time I click on that button.当我在 Pycharm 上运行此代码时,它运行得很好,但是当我使用 pyinstaller 将其设为 a.exe 时,它停止工作,并且每次单击该按钮时它都会打开另一个 window。 I fixed this error by putting my code inside name == " main ", but when I make it an.exe, it gets the same error than when I didn't have that.
我通过将我的代码放入name == " main " 中修复了这个错误,但是当我将它设为 an.exe 时,它得到的错误与我没有它时相同。
Heeeeelp!!!嘻嘻!!!
I had a similar issue, but when my multithread function was called it created a new root
for each process.我有一个类似的问题,但是当我的多线程 function 被调用时,它为每个进程创建了一个新的
root
。 multiprocessing
freeze_support()
was the answer, read the docs here multiprocessing
freeze_support()
是答案,请在此处阅读文档
if __name__ == '__main__':
multiprocessing.freeze_support() # to stop exe popups when threaded
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.