How to create a directly-executable cross-platform GUI app using Python(Tkinter)?


Python is a programming language which can be used to create cross-platform applications that are supported in various operating systems such as Microsoft Windows, Mac OS, and Linux.

To create a GUI-based application, we can use the Tkinter library. However, Python provides different modules and extensions which convert a program into an executable application.

  • For Windows executables - PyInstaller, py2exe

  • For Linux executables - Freeze

  • For Max executables - py2app

Example

For this example, we will first install the PyInstaller module using pip in our Windows operating system. The module can be installed by using the command,

pip install pyInstaller

Using this module, we will convert our application into an executable file.

app.py

In this application, we will ask the user to select Particular days from the list.

# Import the required libraries
from tkinter import *

# Create an instance of tkinter frame
win = Tk()

# Set the size of the tkinter window
win.geometry("700x350")

# Add a Label
Label(win, text="Select a Day from the Menu",
   font=('Aerial 13')).pack(pady=10)

# Create a Variable to store the selection
var = StringVar()

# Create an OptionMenu Widget and add choices to it
option = OptionMenu(win, var, "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
option.config(bg="gray81", fg="white")
option['menu'].config(bg="green3")
option.pack(padx=20, pady=30)

win.mainloop()

Output

Steps to Create Executable File in Python

  • Open the command prompt in the directory and write the command for creating an executable file,

pyinstaller app.py
  • It will create a folder that contains an executable file app.exe. Open the file to run the application.

Updated on: 18-Jun-2021

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements