Home > Software design >  My multithread tkinter code only works when I run it on Pycharm, not in an .exe. It opens an unwante
My multithread tkinter code only works when I run it on Pycharm, not in an .exe. It opens an unwante

Time:08-04

I have multiple files in this project, and, in this particular case, I call a function from another file.

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. 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.

Heeeeelp!!!

CodePudding user response:

I had a similar issue, but when my multithread function was called it created a new root for each process. multiprocessing freeze_support() was the answer, read the docs here

if __name__ == '__main__':
    multiprocessing.freeze_support() # to stop exe popups when threaded
  • Related