In this tutorial, we will learn how to create a standalone Python EXE executable for a Python Tkinter GUI application. This will allow you to distribute your GUI application to users who do not have Python installed on their systems.
Step 1: Install the necessary libraries
First, you will need to install two libraries: pyinstaller and pywin32. Pyinstaller is a tool that can convert Python scripts into standalone executables, and pywin32 is a library that enables Pyinstaller to work correctly with Tkinter.
You can install these libraries using pip by running the following commands in your terminal:
pip install pyinstaller
pip install pywin32
Step 2: Create your Python Tkinter GUI application
Next, you will need to create your Python Tkinter GUI application. For the purposes of this tutorial, we will create a simple calculator application. Here is an example code for a basic calculator GUI:
import tkinter as tk
def calculate():
result.set(eval(expression.get()))
root = tk.Tk()
root.title("Calculator")
expression = tk.StringVar()
result = tk.StringVar()
entry = tk.Entry(root, textvariable=expression)
entry.pack()
button = tk.Button(root, text="Calculate", command=calculate)
button.pack()
label = tk.Label(root, textvariable=result)
label.pack()
root.mainloop()
Save this code in a file named calculator.py
.
Step 3: Create the executable
Now that you have created your Python Tkinter GUI application, you can use Pyinstaller to create a standalone executable. In your terminal, navigate to the directory where your calculator.py
file is located and run the following command:
pyinstaller --onefile --windowed calculator.py
This command tells Pyinstaller to create a standalone executable with a single file (--onefile
) and to hide the console window (--windowed
).
After running this command, Pyinstaller will generate a dist
folder in the same directory as your Python script. Inside this folder, you will find the standalone executable file for your GUI application.
Step 4: Distribute your executable
You can now distribute your standalone executable to users who do not have Python installed on their systems. Simply share the executable file with them, and they will be able to run your Python Tkinter GUI application without any additional setup.
In conclusion, creating a standalone Python EXE executable for a Python Tkinter GUI application is a straightforward process that allows you to easily share your GUI applications with others. By following the steps outlined in this tutorial, you can create and distribute standalone executables for your Tkinter applications with ease.
This is awesome. Like and subscribed to my best presentation ever!
Do you have a video of how to compile multiple .py into an exe, I also am using CTk as well. I tried pyinstaller but its missing dependencies
You are on windows right ? in mac it doesnt bring all the necessary files like this, I mean I cannot share it with others
i save the file as .pyw and run pyinstaller with window defender had to be turned off before finding this video ðŸ˜
Sir ,I can't access the e.get ,it show nonetype attribute error
you can do –noconsole will also have the cmd not pop up!
I am making an exe that checks if python is installed in the computer and i am making the exe in python.. is it possible ?? if so how ?
Thanks for answering
Well, but if you have to add a database for example tree_crm.db to the exe..how can we proceed in pyinstaller ?
How to fix windows defender flag it as a virus
not received
The file that I installed needed SQLite database to work, and when I run the project I installed it can't connect to the database, how do I fix this?
I am getting Invalid syntax error.
not sure why this is happening
Hello, I have created an app in Python which must connect to a database, but I want to extract the credentials from the code and make an executable to put it into production. The problem is that one way or another the user has access to the credentials, whether they put them in the code or include the .env file with the executable. Anyway, I don't know what to do to prevent users from having access to the credentials, I would like to know how I can do so that only the app has access to the credentials. Greetings.
Is there any fix nowaday to get rid of the virus alert this cause wich is not a virus the .exe i mean
Thanks for the explanation. For some reason after installing pyinstaller through pip, I keep getting "No module named 'pyinstaller'"
-w
Where can I distribut my GUI App?
Or possibly how can I host my GUI app?
Where do I host my Tkinter GUI App?