py folder to exe code example

Example 1: how to make a python exe

pip install pyinstaller

cd YourFilePath

pyinstaller --onefile YourFileName

Example 2: how to convert .py file to .exe

Hold shift and right click where your python file is located
and then type

pyinstaller 'fileName.py'
to convert to a simple exe file the exe file will be in your dist folder

pyinstaller --onefile 'fileName.py'
to convert to a onefile exe file the exe file will be in your dist folder

pyinstaller -w --onefile 'fileName.py'
to convert to a onefile exe file and the python window will not appear

# {(NOTE: DON'T DO THIS IF YOU PROGRAM IS CONSOLE BASED)}
# {(IF YOU HAVE MADE A GAME USING PYGAME OR USING ANYTHING ELSE
#   WHERE CONSOLE IS NOT USED THEN IT'S FINE)}
# For more help you can click the link bellow
# It's 12 min tutorial of codewithharry

Example 3: how to save python file as exe

import tkinter as tk

root= tk.Tk()

canvas1 = tk.Canvas(root, width = 300, height = 300)
canvas1.pack()

def hello ():  
    label1 = tk.Label(root, text= 'Hello World!', fg='green', font=('helvetica', 12, 'bold'))
    canvas1.create_window(150, 200, window=label1)
    
button1 = tk.Button(text='Click Me',command=hello, bg='brown',fg='white')
canvas1.create_window(150, 150, window=button1)

root.mainloop()