I am creating an app while converts python files to exe files.
I am trying to use os.system()
method, but it displays the console window, which I don't want.
What I want to do:
- Hide the console window
- Add a progress bar (if possible)
- Prevent the app from going 'Not responding' (hanging).
- Send a notification to the user after the exe is created (I can use
win10toasts
module for this)
How can I do that?
Here's the current code:
from tkinter import Tk, messagebox as mb
from tkinter.ttk import Button, Label
import os
root = Tk()
root.title("Creating exe")
root.geometry("500x500")
def create_exe_onefile(item):
try:
if os.path.exists(pyinstaller_path) or os.path.exists(pyinstaller_path2):
pass
else:
os.system("pip install pyinstaller")
if os.path.exists("Apps Created\\Executables"):
pass
else:
os.mkdir("Apps Created\\Executables")
os.system(f'pyinstaller --onefile -w "{item}"')
path = fd.askdirectory(title="Where to save the exe?")
if path:
fi = item.replace('.pyw', '')
try:
os.mkdir(f"Apps Created\\Executables\\{fi}")
except Exception:
pass
for j in os.listdir(f"build\\{fi}"):
os.remove(j)
os.rmdir(f"build\\{fi}")
os.rmdir("build")
shutil.move(f"dist\\{item}", f"Apps Created\\Executables\\{fi}")
for i in os.listdir(f"dist\\{fi}"):
os.remove(i)
os.rmdir(f"dist\\{fi}")
os.rmdir("dist")
for i in os.listdir("__pycache__"):
os.remove(i)
os.rmdir("__pycache__")
os.remove(f"{fi}.spec")
shutil.copytree(f"Apps Created\\Executables\\{fi}\\{item}", path)
mb.showinfo("Done", f"File copied.\nYou can find your exe file in {path}.\nA copy of your exe has been saved in {os.getcwd()}\\Apps Created\\Executables")
except Exception as err:
mb.showerror("Error", f"Error while creating the exe!\n{err}")
exit()
status = Label(root, text="Please wait while the exe is being created...", font="Calibri 20")
status.pack(pady=50)
stb = Button(root, text="Start", command=lambda: convert_exe_onefile("main.pyw"))
stb.pack(pady=30)
# If possible, I want to add a progressbar here to show the status of exe creation.
root.mainloop()