1

As suggested here I use it to hide my command prompt in my setup.py file. It does hide my command prompt but the app does not work. Basically I am trying to make a Windows native Microsoft MSI for my GUI that I have built for youtube-dl command line tool that is used to consume media from some of the most popular video hosting sites. Any help is much appreciated. Here is my app.py:-

from tkinter import *
from tkinter import ttk
from tkinter import messagebox
from tkinter import filedialog
from tkinter.ttk import Progressbar
import youtube_dl
import threading
import os

download_folder = os.path.expanduser("~")+"/Downloads/"
download_folder_chosen = ""

window = Tk()

window.title("IOB Youtube Downloader")
window.geometry('510x100')

def my_hook(d):
    if d:
        if d['status'] == 'downloading':
            percent_done = d['_percent_str']
            percent_done = percent_done.replace(" ", "")
            percent_done = percent_done.replace("%", "")
            bar['value'] = percent_done     
            bar.grid(column=1, row=2, pady=15)
            bar_lbl.configure(text=percent_done + "%")
            bar_lbl.grid(column=1, row=3)
            txt['state'] = DISABLED 
            btn['state'] = DISABLED 
        if d['status'] == 'finished':
            bar.grid_forget()
            txt['state'] = NORMAL 
            btn['state'] = NORMAL
            bar_lbl.configure(text="Download Completed !!!")
            bar_lbl.grid(column=1, row=2)
            messagebox.showinfo('IOB Youtube Downloader', 'Download Complete')
        if d['status'] == 'error':
            print("\n"*10)
            print(d)
            messagebox.showerror('IOB Youtube Downloader', 'Download Error')

    else:
        bar_lbl.configure(text="Download Error. Please try again !!!")
        bar_lbl.grid(column=1, row=2)


def start_thread():
    t1 = threading.Thread(target=clicked, args=())
    t1.start()

def clicked():
    res = txt.get()
    if download_folder_chosen != "":
        location = download_folder_chosen + "/"
    else:
        location = download_folder
    ydl_opts = {
        'progress_hooks': [my_hook],
        'format': 'best',
        'outtmpl': location + u'%(title)s-%(id)s.%(ext)s',
    }
    try:
        with youtube_dl.YoutubeDL(ydl_opts) as ydl:
            ydl.download([res])
    except:
        messagebox.showerror('IOB Youtube Downloader', 'Download Error')

def choose_directory():
    global download_folder_chosen
    current_directory = filedialog.askdirectory()
    download_folder_chosen = current_directory
    messagebox.showinfo('IOB Youtube Downloader', 'Download Location:- ' + download_folder_chosen)

style = ttk.Style() 
style.theme_use('default')
style.configure("blue.Horizontal.TProgressbar", background='blue') 
bar = Progressbar(window, length=200, style='black.Horizontal.TProgressbar')

bar_lbl = Label(window, text="")


lbl = Label(window, text="Paste URL")
lbl.grid(column=0, row=0)

txt = Entry(window,width=60)
txt.grid(column=1, row=0)

btn = Button(window, text="Download", command=start_thread)
btn.grid(column=2, row=0)

btn2 = Button(window, text="...", command=choose_directory)
btn2.grid(column=3, row=0)

window.iconbitmap('favicon.ico')
window.mainloop()

And here is my setup.py file that I use to build the bundle exe using cx_Freeze.

from cx_Freeze import setup, Executable
import sys
import os

base = None
if sys.platform == 'win32':
    base = "Win32GUI"

os.environ["TCL_LIBRARY"] = r"C:\Python35\tcl\tcl8.6"
os.environ["TK_LIBRARY"] = r"C:\Python35\tcl\tk8.6"

setup(
    name = "IOB Youtube Downloader",
    options = {"build_exe": {"packages":["tkinter",], "include_files":[r"C:\Python35\DLLs\tk86t.dll", r"C:\Python35\DLLs\tcl86t.dll", r"E:\Youtube_Downloader\Src\favicon.ico"]}},
    version = "1.0",
    author = "IO-Bridges",
    description = "Download videos from all popular video streaming sites.",
    executables = [Executable
                            (
                                r"downloader.py",
                                # base=base,  <---- Here setting the base  
                                shortcutName="IOB Youtube Downloader",
                                shortcutDir="DesktopFolder",
                                icon="favicon.ico"
                            )]
    )
Shashishekhar Hasabnis
  • 1,636
  • 1
  • 15
  • 36
  • What errors do you get when running through command prompt? – Xantium Feb 05 '18 at 23:58
  • I cant see errors as I hide my command prompt as I mentioned in the link [https://stackoverflow.com/questions/5523867/hide-console-window-with-tkinter-and-cx-freeze] that suggested how I could I hide my command prompt. However when I don't hide my command prompt it does not give me any errors. It works smoothly. – Shashishekhar Hasabnis Feb 06 '18 at 05:39
  • So you're saying that your app doesn't work when command prompt is hidden only? How does it not work, what is different than it's working state? Have you tried running the .exe on command prompt? No errors still? – Nae Feb 06 '18 at 10:24
  • Yes the app doesn't work only when the command prompt is hidden. Yes I have also tried executing the .exe on command prompt but it does not log any errors. – Shashishekhar Hasabnis Feb 08 '18 at 05:09

0 Answers0