pyinstaller EXE opens 2 console windows for a child process

584 views Asked by At

I made a YouTube video downloader that uses cmd to run youtube-dl in a new console window. When I run the program by itself it works perfectly, but when I freeze it and hit the download button, it opens two console windows and runs the program in only one of them. The other just sits there until the program ends.

Here is my code entirely. Be gentle I'm still very new.

from tkinter import *
from tkinter import filedialog
import os


class MyApp:
    def __init__(self, parent):
        # -----------Main window--------------------
        self.mainwindow = Frame(parent)
        self.mainwindow.pack(expand=YES, fill=BOTH)

        # -----------Frames--------------------
        self.topFrame = Frame(self.mainwindow, bg="gray20")
        self.topFrame.pack(side=TOP, expand=YES, fill=BOTH)

        self.midFrame = Frame(self.mainwindow, bg="gray20")
        self.midFrame.pack(side=TOP, expand=YES, fill=BOTH)

        self.URLframe = Frame(self.midFrame, bg="gray20")
        self.URLframe.pack(side=TOP, expand=YES, fill=BOTH)

        self.folderframe = Frame(self.midFrame, bg="gray20")
        self.folderframe.pack(side=TOP, expand=YES, fill=BOTH)

        self.bottomFrame = Frame(self.mainwindow, bg="gray20")
        self.bottomFrame.pack(side=BOTTOM, expand=YES, fill=BOTH)

        # -----------Top label--------------------
        self.Toplabel = Label(self.topFrame,
                              text="YouTube Hoarder", font=("Courier", 44),
                              fg="blue2", bg="gray20",
                              height=3, width=50,
                              )
        self.Toplabel.pack()

        # -----------URL entry--------------------
        self.URL_entry = Entry(self.URLframe, width=90)
        self.URL_entry.focus_force()
        self.URL_entry.pack(side=RIGHT, padx=15)

        self.URL_text = Label(self.URLframe,
                              text="Gimme URL",
                              height=1, width=10,
                              bg="light blue"
                              )
        self.URL_text.pack(side=LEFT, pady=6)

        # -----------folder entry--------------------
        self.DirVar = StringVar(self.mainwindow)

        self.folder_entry = Entry(self.folderframe, width=90,
                                  textvariable=self.DirVar)
        self.folder_entry.pack(side=RIGHT, padx=15)

        self.folder_text = Label(self.folderframe,
                                 text="Gimme folder",
                                 height=1, width=10,
                                 bg="light blue"
                                 )
        self.folder_text.pack(side=LEFT, pady=6)

        # -----------buttons--------------------
        self.Download_button = Button(self.bottomFrame,
                                      text="Download",
                                      width=20, height=4,
                                      bg="light green",
                                      command=self.download_process
                                      )
        self.Download_button.pack(side=RIGHT)

        self.find_folder_button = Button(self.midFrame,
                                         text="Folder Directory",
                                         width=12, height=2,
                                         bg="light green",
                                         command=self.print_message2
                                         )
        self.find_folder_button.pack(side=RIGHT, padx=5)

        # -----------options menu--------------------
        self.Type_list = ["best", "mp3", "mp4"]
        self.Variable = StringVar(self.mainwindow)
        self.Variable.set(self.Type_list[0])
        self.file_option = OptionMenu(self.bottomFrame, self.Variable,
                                      *self.Type_list)
        self.file_option.pack(side=LEFT)

    def print_message2(self):
        self.dir_opt = options = {}
        options['initialdir'] = 'Downloads'

        self.DirName = filedialog.askdirectory(**self.dir_opt)
        self.DirVar.set(self.DirName)

    def download_process(self):
        self.givenURL = self.URL_entry.get()
        self.givenFT = self.Variable.get()
        os.system('start /wait cmd /c youtube-dl --output '
                  '"{0}\%(title)s.%(ext)s" -i -f '
                  '{1}/best --yes-playlist "{2}"'.format(
                  self.DirName, self.givenFT, self.givenURL))

root = Tk()
root.resizable(width=False, height=False)
root.geometry("{}x{}".format(700 , 400))
root.title("YouTube Hoarder")
root.iconbitmap(r'C:\Users\tjhall\Downloads\LT3WE.ico')
myapp = MyApp(root)
root.mainloop()
0

There are 0 answers