- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to bundle a Python Tkinter application including dependencies?
Let us suppose we have created a tkinter application and now, we want to bundle the standalone application to make it portable and executable. We can use different Python packages that support various functionality to bundle the whole application code into an executable installer. These packages compress the code and convert the standalone application into an executable code.
For a Windows-based user, we can use py2exe; for Linux, we can use Freeze; and for Mac, we can use py2app.
Example
In this example, we have created a Windows-based application that prints “Hello World” on the screen. Initially, we will create a setup.py file in the same directory where the main application file exists. Then, we will extend the functionality of the main application file by passing the filename as the parameter in the setup.py.
setup.py
from distutils.core import setup import py2exe setup(console=['main_app.py'])
Now, type and run setup.py with the py2exe package in the command shell. After running the command, it will create a dist folder in the same directory which contains an executable file named as “main_app.exe”.
main_app.py
#Import the tkinter library from tkinter import * #Create an instance of tkinter frame win = Tk() #Set the geometry win.geometry("600x400") def present(): Label(win, text="Hello World", font=('Times New Roman bold',30)).pack(pady=10) Button(win, text="Click Me", command= present).pack(pady=20) win.mainloop()
Output
Running the main_app.exe file will open the following window with a Button and a Label in it.
- Related Articles
- How to create a borderless fullscreen application using Python-3 Tkinter?
- How to make a system tray application in Tkinter?
- Good example of functional testing a Python Tkinter application
- How to set the tab order in a Tkinter application?
- How to display a tkinter application in fullscreen on macOS?
- How to create a System Tray icon of a Tkinter application?
- How we can bundle multiple python modules?
- How to install python modules and their dependencies easily?
- Creating Tkinter full-screen application
- How do I change the overall theme of a tkinter application?
- How to use resource bundle in JSP?
- Inheriting from Frame or not in a Tkinter application
- How to update a Python/tkinter label widget?
- How to use multiple resource bundle in same JSP?
- When do I need to call the main loop in a Tkinter application?
