🐍 Python UI Programming Series — Part 8: Packaging Your Tkinter App into a Standalone Executable (.exe)
📘 Overview
You’ve built a full-featured GUI application with Tkinter. Now it’s time to share your app with the world — without requiring users to install Python.
In this part, you’ll learn how to:
-
Turn your
.py
Tkinter script into a.exe
file -
Use
pyinstaller
to package apps -
Add icons, hide the terminal, and manage dependencies
🔧 Tool Required: PyInstaller
✅ What is PyInstaller?
-
A tool to convert Python scripts into standalone executables
-
Supports Windows, macOS, and Linux
-
Bundles all required files into one folder or single
.exe
✅ Step 1: Install PyInstaller
Open your terminal or command prompt and run:
pip install pyinstaller
✅ Step 2: Basic Packaging Command
Navigate to the folder containing your script (app.py
, for example) and run:
pyinstaller app.py
This generates:
-
A
dist/
folder with your.exe
file inside -
A
build/
folder with intermediate files -
A
.spec
file (you can edit this for advanced control)
🧰 Step 3: Common PyInstaller Options
Option | Purpose |
---|---|
--onefile |
Bundle into a single .exe file |
--noconsole |
Hide the terminal window (useful for GUI apps) |
--icon=icon.ico |
Add a custom app icon |
Example:
pyinstaller --onefile --noconsole --icon=myicon.ico app.py
📁 Step 4: Distribute Your App
After packaging:
-
Go to the
dist/
folder -
Your
app.exe
is ready to run on any Windows machine 🎉
You can now share it:
-
On email, cloud drives, GitHub releases, or USB
-
With instructions like: “Just double-click to open”
🛑 Note: Antivirus software may flag new .exe
files — this is common and not usually dangerous if you made the file.
🧩 Optional: Add Data Files (images, DB, etc.)
If your app uses images or a database file, update your .spec
file or run:
pyinstaller --add-data "data.db;." --onefile app.py
Use ;
on Windows and :
on macOS/Linux to separate file paths.
💡 Recap
In this part, you’ve learned:
-
How to convert your Tkinter GUI app to a Windows
.exe
-
How to use PyInstaller for packaging
-
Tips for hiding the terminal and adding icons
🎉 Congratulations!
You’ve now completed a full journey:
-
GUI creation and layout
-
Widget styling and form validation
-
Database integration
-
Advanced widgets
-
Packaging for distribution
👏 You’ve essentially built a real desktop application from scratch!
No comments:
Post a Comment