In this lesson we want to learn How to Build Python GUI with PySimpleGUI, PySimpleGUI is Python package that makes it easy to create graphical user interfaces (GUIs) for your Python programs. this is an example of how to create simple GUI using PySimpleGUI:
- First, install the PySimpleGUI package using pip:
1 |
pip install pysimplegui |
- Next, import the package:
1 |
import PySimpleGUI as sg |
- Now, create layout for your GUI. You can use the sg.Layout method to create layout using the element types provided by the package, such as buttons, text boxes and labels. for example:
1 2 3 4 5 |
layout = [ [sg.Text('Enter your name:')], [sg.InputText()], [sg.Button('OK'), sg.Button('Cancel')] ] |
- Create the window by calling sg.Window method and passing in the layout title for the window and any other optional parameters you want to specify. for example:
1 |
window = sg.Window('My GUI', layout) |
- Use read method to handle user input and events in the window. for example following code will display the window and wait for the user to click the OK or Cancel button:
1 |
event, values = window.read() |
- Use an if statement to check the value of event variable, and then perform the appropriate action based on the button that was clicked. for example:
1 2 3 4 |
if event == 'OK': print('Hello, ' + values[0]) else: print('Goodbye!') |
- Close the window with close() method
1 |
window.close() |
This is just basic example of how to create GUI using PySimpleGUI. you can also add more elements to your layout, create custom styles for your elements and handle more complex events and user input.
You can find more information about PySimpleGUI on the package’s website, which includes documentation and a lot of examples.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
import PySimpleGUI as sg layout = [ [sg.Text('Enter your name:')], [sg.InputText()], [sg.Button('OK'), sg.Button('Cancel')] ] window = sg.Window('My GUI', layout) event, values = window.read() if event == 'OK': print('Hello, ' + values[0]) else: print('Goodbye!') window.close() |
This is an example of how you would create simple window with label, an input text and two buttons, when clicking on the OK button the program will print the text written in the input box and if you click the cancel button it will print goodbye.
Run the complete code and this will be the result

Learn More on Python GUI Development
- Build Text to Speech App with Python & PyQt5
- How to Build GUI Window in PyQt6
- How to Show Image in PyQt6
- How to Create Calendar with Python & PyQt6
- How to Create CheckBox in PyQt6
What are the Pros and Cons of PySimpleGUI
PySimpleGUI is popular package for creating graphical user interfaces (GUIs) in Python. these are some pros and cons of using PySimpleGUI:
Pros:
- PySimpleGUI is easy to use even for beginners with little to no experience with GUI development.
- PySimpleGUI has large different types of elements that can be used to create GUI including buttons, labels, text boxes and more.
- PySimpleGUI supports different platforms such as Windows, Linux and macOS.
- PySimpleGUI is lightweight and has small footprint.
- PySimpleGUI has good documentation and a lot of examples.
Cons:
- PySimpleGUI is wrapper for tkinter, wxPython and PyQt, so it might not have the same level of customization as working directly with one of those frameworks.
- PySimpleGUI’s widgets are not as modern looking as other frameworks like Qt, so if you want more polished look it might not be the best option.
- PySimpleGUI does not support mobile platforms like Android or iOS.
- PySimpleGUI does not have designer that allows you to create the UI directly from visual editor.
In result we can say that PySimpleGUI is good choice for creating simple and lightweight GUIs for desktop applications. If you are looking for more feature rich framework, or need to support mobile platforms, you may want to consider other options like PyQt or Kivy.