PySimpleGUI graphical interfaces for creation of software.

In the command line / terminal type: pip install pysimplegui wait for the installation to complete, enter the python environment, type import PySimpleGUI and confirm the successful installation.

PySimpleGUI can use several bindings, one of them is tk. To install tk you can use the command sudo apt install python3.6-tk. Other bindings include web and qt.

Related course: Desktop Apps made Simple with Python (PySimpleGUI)

Create a simple pop-up window interface. The default library abbreveation is sg, and it is recommended to use this name when using it.

import PySimpleGUI as sg
sg.popup("Hello World")

PySimpleGUI popup

There are many popup types, a demo is shown below.

sg.popup_ok('Default popup')
sg.popup_yes_no('Popup with Yes and No buttons')
sg.popup_cancel('Popup with cancel button')
sg.popup_ok_cancel('Popup with OK and cancel buttons')
sg.popup_error('popup with red error button')
sg.popup_auto_close('Popup window that closes automatically after a few seconds')

You can set custom parameters. For example, setting up a small customized window:

    button_color=('#A81B0C', '#FFFFFF'),

Text content popup window

Use the popup_scrolled() method, and add the content to be displayed in parentheses

text = "Hello"

popup with text

Get user input

Using the PySimpleGUI popup_get_text() method, you can get user input. It is somewhat similar to the prompt in the input() statement, reminding the user to enter text.

text1 = sg.popup_get_text('Enter text1: ')
text2 = sg.popup_get_text('Enter text2: ')

User input with GUI

Test for hidden password input, you can get the user input password in the form of a pop-up window:

text = sg.popup_get_text('Enter password', password_char='*')

Password input in Python

File selection popup window

Use the sg.popup_get_file() method to select a file.

path = sg.popup_get_file('Select a file')

Open file with PySimpleGUI

You can add paramters:

  • message
  • default_path
  • save_as (bool)
  • multiple_files (bool)
  • file_types
  • initial_folder


You can change those parameters directly in the function call

path = sg.popup_get_file( 'Select a file', save_as=True, default_extension='zip', file_types(('ZIP files´,'.zip'), ) ) print(path)

Select directory window

The sg.popup_get_folder() method is used as an input prompt to select a folder. After executing the program, a window for selecting files will pop up, and the path of the folder will be added to the input box after selection.

path = sg.popup_get_folder('Select folder')

select folder

Progress bar pop-up window

Use the sg.one_line_progress_meter() method, and enter the relevant parameter settings in parentheses.

for i in range(1000):
        i + 1,
        'this progress bar key',
        'this is a progress bar'

Progressbar GUI with Python

You can change the orientation and colors

for i in range(1, 1000):
        i + 1,
        'this progress bar key',
        'this is a progress bar',
        bar_color=('#F47264', '#FFFFFF')

Horizontal progressbar with changed colors