Tkinter opens unwanted new window with Pyinstaller

  pyinstaller, python, tkinter

I try to make a download interface via tkinter. The following code works well in Pycharm. But when I try to make it an exe file using pyinstaller, it opens a new window every time I click on button1(the download button), which is undesired. Could you please tell me how to fix it? I’m working on Win10. Thanks in advance.

import tkinter as tk
from download import download_yv as dyv
import multiprocessing

class DownloadPage(tk.Frame):
    def __init__(self, parent):
        tk.Frame.__init__(self, parent)
        self.grid()
        self.download_flag=True
        self.current_row=0
        self.current_rowspan=0

        self.label1=tk.Label(self,text='Url:',)
        self.label1.grid(row=self.current_row,column=0,)

        self.text1=tk.Entry(self,width=45)
        self.text1.grid(row=self.current_row,column=1,padx=0,pady=0)

        self.current_row+=1
        self.label2=tk.Label(self,text='Save_Dir:',wraplength=200,)
        self.label2.grid(row=self.current_row,column=0)

        self.text2=tk.Entry(self,width=45)
        self.text2.grid(row=self.current_row,column=1,padx=0,pady=0,)

        self.current_row+=1
        self.label3=tk.Label(self,text='Overwrite:',)
        self.label3.grid(row=self.current_row,column=0)

        self.var1=tk.BooleanVar(self)
        self.var1.set('False')
        self.menu1=tk.OptionMenu(self,self.var1,'True','False')
        self.current_rowspan=2
        self.menu1.grid(row=self.current_row,column=1,columnspan=2,rowspan=self.current_rowspan,sticky='news')

        self.current_row+=self.current_rowspan
        self.label4=tk.Label(self,text='Categorize:')
        self.label4.grid(row=self.current_row,column=0)

        self.var2 = tk.BooleanVar(self)
        self.var2.set(True)
        self.menu2=tk.OptionMenu(self,self.var2,'True','False')
        self.menu2.grid(row=self.current_row,column=1,columnspan=2,rowspan=self.current_rowspan,sticky='news')

        self.current_row+=self.current_rowspan
        self.current_rowspan=2
        self.button1=tk.Button(self,text='download',command=self.download)
        self.button1.grid(row=self.current_row,column=1,columnspan=2,rowspan=self.current_rowspan,sticky='news')

        self.current_row+=self.current_rowspan
        self.button2=tk.Button(self,text='Stop Downloading',command=self.stop_download)
        self.button2.grid(row=self.current_row,column=1,columnspan=1,)

    def download(self):
        var1=self.var1.get()
        var2=self.var2.get()
        # print(var1,type(var1),var2,type(var2))
        self.download_process=multiprocessing.Process(target=dyv,args=(self.text1.get(),self.text2.get(),var1,var2))
        self.download_process.start()


    def stop_download(self):

        if self.download_process and self.download_process.is_alive():
            self.download_process.terminate()

if __name__ == '__main__':
    root=tk.Tk()
    app=DownloadPage(root)
    app.mainloop()

Source: Python Questions

LEAVE A COMMENT