VOOZH about

URL: https://thenewstack.io/python-for-beginners-how-to-build-a-gui-application/

⇱ Python for Beginners: How to Build a GUI Application - The New Stack


TNS
SUBSCRIBE
Join our community of software engineering leaders and aspirational developers. Always stay in-the-know by getting the most important news and exclusive content delivered fresh to your inbox to learn more about at-scale software development.
REQUIRED
It seems that you've previously unsubscribed from our newsletter in the past. Click the button below to open the re-subscribe form in a new tab. When you're done, simply close that tab and continue with this form to complete your subscription.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.
Welcome and thank you for joining The New Stack community!
Please answer a few simple questions to help us deliver the news and resources you are interested in.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Great to meet you!
Tell us a bit about your job so we can cover the topics you find most relevant.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Welcome!

We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.

What’s next?

Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.

Follow TNS on your favorite social media networks.

Become a TNS follower on LinkedIn.

Check out the latest featured and trending stories while you wait for your first TNS newsletter.

PREV
1 of 2
NEXT
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
Thanks for your opinion! Subscribe below to get the final results, published exclusively in our TNS Update newsletter:
NEW! Try Stackie AI
From clobbered drafts to real-time sync
Apr 14th 2026 10:00am, by David Moore
TypeScript 6.0 RC arrives as a bridge to a faster future
Mar 14th 2026 9:00am, by Darryl K. Taft
Mastra empowers web devs to build AI agents in TypeScript
Jan 28th 2026 11:00am, by Loraine Lawson
2022-04-01 11:00:11
Python for Beginners: How to Build a GUI Application
tutorial,
Data / Software Development / Storage

Python for Beginners: How to Build a GUI Application

How to build a GUI for your Python application.
Apr 1st, 2022 11:00am by Jack Wallen
👁 Featued image for: Python for Beginners: How to Build a GUI Application

So far, in our Python for Beginners series, we’ve discussed many aspects of Python, such as lists, variables, tuples, functions, reading text from files, and so much more.

The one common denominator with the tutorials so far is that we’re only building text-based applications. Those applications are great and can come in very handy (especially on machines that don’t include a desktop environment or you need them to work in the background). You might even believe that Python isn’t capable of building apps with graphical user interfaces (GUIs).

Guess what? It is.

These GUI apps are capable of using things like:

  • radio buttons
  • checklists
  • menus
  • dropdown lists
  • value wheels
  • value bars
  • and more

With just a little help from a GUI toolkit, you can create GUI applications with Python. Don’t believe me? Let me show you how it’s done.

I’ll be demonstrating on Pop!_OS Linux, but this can be done with any distribution that supports Python.

Install PySimpleGUI

Before we can create any GUI applications with Python, we have to install a Python library that wraps various GUI libraries (such as Tkinter, Qt (pyside2), wxPython, and Remi) in a single package to allow for fast and simple GUI programming. Out of the box, PySimpleGUI defaults to Tkinter, but you can switch it up as needed.

In other words, installing PySimpleGUI gives you everything needed to start building GUI applications with Python.

To install PySimpleGUI, you’ll need a machine that already has Python installed. You’ll also need pip available for the installation. If you’ve not already installed pip, do so with the command:

sudo apt-get install python3-pip -y

With Pip installed, you can now install PySimpleGUI with the command:

python3 -m pip install pysimplegui

At this point, you are ready to start building your first GUI application.

Hello, New Stack!

The first GUI application we’ll build is the always popular Hello, World (with a New Stack twist). The first thing you must know is that the PySimpleGUI library must be imported into your application. We’ve done this before, so it should be second nature.

We’ll import PySimpleGUI into our application as sg with the line:

import PySimpleGUI as sg

With that line, we can call any PySimpleGUI function with just sg.

Our next line will define the layout of a button for the application. This line will define the text for the button as “Hello, New Stack” and the size of the button as 30 x 4. This line looks like this:

layout = [[sg.Button('Hello, New Stack', size=(30,4))]]

Notice the line uses a tuple (what’s within ()) and a list (what’s within []) to draw the button.

Our next line draws the actual window for the application and looks like this:

window = sg.Window('GUI SAMPLE', layout, size=(200,100))

What you see above is a variable (window) that uses the PySimpleGUI function Window to draw a graphical element labeled GUI SAMPLE with a size 200×100.

Finally, we use the .read() function (which returns the specified number of bytes from the file. the Default is -1 which means the whole file) to act on a button click with the line:

event, values = window.read()

Our whole script (with comments) looks like this:

#Import PySimpleGUI
import PySimpleGUI as sg

#Draw the button
layout = [[sg.Button('Hello, New Stack', size=(30,4))]]

#Draw the window
window = sg.Window('GUI SAMPLE', layout, size=(200,100))

#Define what happens when the button is clicked
event, values = window.read()

Save that file as hello_world.py. Run the program with the command:

python3 hello_world.py

What you should then see is a small window with a clickable button (Figure 1).

👁 Python GUI

Figure 1: Our GUI Python Hello, World application.

Click the Hello, New Stack button and the window will close.

Accepting User Input

This time around, we’ll create a GUI that accepts user input. This time we’ll import Tkinter package (which was installed with PySimpleGUI) to do the heavy lifting. Let’s call this file input_gui.py. The first line imports Tkinter and looks like this:

import tkinter as tk

Next, we’re going to import simpledialog from Tkinter with:

from tkinter import simpledialog

We then define the root window with:

ROOT = tk.Tk()

With the root window defined, we can then define the input dialog (naming the window “Input Test”) and prompt the user to type their name with:

USER_INP = simpledialog.askstring(title="Input Test",
                                  prompt="Type your Name:")

Finally, we print out the user input back in the terminal window with the line:

print("Hello", USER_INP)

Our entire application looks like this:

# Import tkinter and simpledialog
import tkinter as tk
from tkinter import simpledialog

# Define the root window
ROOT = tk.Tk()

# Define input dialog
ROOT.withdraw()

# Define the input dialog
USER_INP = simpledialog.askstring(title="Input Test",
                                  prompt="Type your Name?:")

# Print the user input
print("Hello", USER_INP)

Save and close the file. Run the app with:

python3 input_gui.py

You will see a small GUI window asking for your name with OK and Cancel buttons (Figure 2).

👁 Image

Figure 2: Our GUI for user input.

Type your name and click OK to see a message printed in the terminal window.

And there you go… you’ve created your first GUI application with Python. As you can see, this user-friendly language isn’t only limited to text-based apps. Python is, in fact, quite a versatile language, which helps to make it even more useful.

TRENDING STORIES
Jack Wallen is what happens when a Gen Xer mind-melds with present-day snark. Jack is a seeker of truth and a writer of words with a quantum mechanical pencil and a disjointed beat of sound and soul. Although he resides...
Read more from Jack Wallen
SHARE THIS STORY
TRENDING STORIES
SHARE THIS STORY
TRENDING STORIES
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.