PySimpleGUI
| Developer(s) | M. Barnett |
|---|---|
| Initial release | 11 July 2018[1] |
| Stable release | |
| Repository | github |
| Written in | Python |
| Engine | |
| Operating system | Cross-Platform |
| License | GNU Lesser General Public License (LGPLV3+) |
| Website | pypi |
Search PySimpleGUI on Amazon.
PySimpleGUI
PySimpleGUI is a wrapper to the Tkinter Python API that allows the programmer to utilize all the same UI elements as with Tkinter but with a more intuitive interface. PySimpleGUI was established in an effort to create a more user-friendly Python GUI development process. PySimpleGUI combines the most effective elements of packages like EasyGUI and WxSimpleGUI, and adds the ability to define custom layouts.[2]
Licensing
PySimpleGUI is OSI approved under the GNU LESSER GENERAL PUBLIC LICENSE V3 OR LATER (LGPLV3+).
Background
Launched in July, 2018, PySimpleUI sought a solution to streamline the Python GUI development efforts and move users from the command line to a windowed / GUI experience.[1] The PySimpleGUI package is focused on the developer, allowing them to create a custom GUI with as concise code as possible.
Features
The PySimpleGUI functions can be split into “High Level” calls that enable the caller to perform input/output operations in a single function call, and “Custom GUI” capabilities. The high-level calls usually start with “Popup”. The most basic of these is Popup which displays a variable number of items in a pop-up window. They resemble the built-in “print” statement, taking any number of variables in any format and displaying them in a window. The Popup calls that gather user input include PopupGetText, PopupGetFile and PopupGetFolder. Custom GUIs are achieved by first creating a “GUI layout” that is used to create and display a Window. The GUI layout is composed of “Elements”, PySimpleGUI’s term for a GUI “Widget”. Elements can be
- Text
- InputText
- Multiline
- InputCombo
- Listbox
- Radio
- Checkbox
- Spin
- Output
- SimpleButton
- RealtimeButton
- ReadFormButton
- FileBrowse
- ProgressBar
- Image
- Slider
- Column
Simplifying and compacting the code can be achieved by leveraging two of PySimpleGUI’s “shortcuts”. Element names can be written in a short-form format. It reduces the amount of text in the code without losing meaning. Abbreviations for elements are:
- T = Text
- Txt = Text
- In = InputText
- Input = IntputText
- Combo = InputCombo
- DropDown = InputCombo
- Drop = InputCombo
A second short-cut mechanism are pre-defined buttons. These are buttons commonly found in all GUIs such as “ok”, “cancel”, “yes”. Rather than writing Button(‘ok’) a button shortcut allows writing Ok(*), Cancel(), Yes(). Button-shortcuts include:
- FolderBrowse
- FileBrowse
- FileSaveAs
- Save
- Submit
- OK
- Ok
- Cancel
- Quit
- Exit
- Yes
- No
- SimpleButton
- ReadFormButton
- RealtimeButton
The "High Level" API calls that output values take a variable number of arguments so that they match a "print" statement as much as possible. The idea is to make it simple for the programmer to output as many items as desired and in any format. The user need not convert the variables to be output into the strings.[3] For full list of features and how to implement them please refer to the CookBook.
Design Goals
PySimpleGUI's goal with the API is to be easy on the programmer, and to function in a Python-like way. Since GUIs are visual, it was desirable for the code to visually match what is on the screen.[2]
Some examples of how this package attempts to use language constructs in a natural way and exploit some of Python's interesting features:
- Forms are represented as Python lists.
- A form is a list of rows
- A row is a list of elements
- Return values are a list of button presses and input values.
- Return values can also be represented as a dictionary
- The SDK calls collapse down into a single line of Python code that presents a custom GUI and returns values[4]
In addition to a Python-like API, the PYSimpleGUI documentation provides a number of example code snippets allowing developers in need to get up and running by copying, pasting, and sometimes modifying the code to create the desired GUI without needing to learn the library prior to use.[2]
Example
PySimpleGUI focuses on the creation of Python native UI in as simple code as possible. When creating UI with PySimpleGUI every call has optional parameters so that you can change the look and feel. Changing a button color can be done by adding a button_color parameter to your widget. The configure is done in-place.
With a simple GUI, it becomes practical to "associate" .py files with the python interpreter on Windows. Double click a py file and up pops a GUI window, a more pleasant experience than opening a dos Window and typing a command line.
Hello World
import PySimpleGUI as sg
sg.MsgBox('Hello From PySimpleGUI!', 'This is the shortest GUI program ever!')

Here is a simple form with 3 text input fields and a couple of buttons.[5]
1 import PySimpleGUI as sg # Very basic form. Return values as a list
2 form = sg.FlexForm('Simple data entry form') # begin with a blank form
3 layout = [
4 [sg.Text('Please enter your Name, Address, Phone')],
5 [sg.Text('Name', size=(15, 1)), sg.InputText('name')],
6 [sg.Text('Address', size=(15, 1)), sg.InputText('address')],
7 [sg.Text('Phone', size=(15, 1)), sg.InputText('phone')],
8 [sg.Submit(), sg.Cancel()]
9 ]
10 button, values = form.LayoutAndRead(layout)
11 print(button, values[0], values[1], values[2])
- line 1: Importing the PySimpleGUI library into your program's namespace, renaming it as 'sg'.
- line 2: Initializing an empty form with the title "Simple data entry form".
- line 3: The starting bracket for the layout defining the widgets that will display in the form.
- line 4: Initializing a label at the top of the form with the text "Please enter your Name, Address, Phone" and adding it to the layout. (The brackets represent a sort of grid like layout on how the UI components will align relative to each other. ex. A label next to a text input field)
- line 5: Initializing a label 'Name' with label size of (15,1) next to a text input field with a default text value of 'name'.
- line 6: Initializing a label 'Address' with label size of (15,1) next to a text input field with a default text value of 'address'.
- line 7: Initializing a label 'Phone' with label size of (15,1) next to a text input field with a default text value of 'phone'.
- line 8: Initializing a 'Submit' button next to a 'Cancel' button.
- line 9: The closing bracket to the layout definition.
- line 10: Adding the layout to the form, displaying the form, and returning the values of what button was pressed along with a list of values entered by the user.
- line 11: Printing the value of what button was pressed, and the values from all 3 text fields in the form.
Below is a more complex example of many widgets used on a single form adhering to the core mantras of PySimpleGUI.
Here is the code that produced the above screenshot.
import PySimpleGUI as sg
with sg.FlexForm('Everything bagel', auto_size_text=True, default_element_size=(40, 1)) as form:
layout = [
[sg.Text('All graphic widgets in one form!', size=(30, 1), font=("Helvetica", 25), text_color='blue')],
[sg.Text('Here is some text.... and a place to enter text')],
[sg.InputText()],
[sg.Checkbox('My first checkbox!'), sg.Checkbox('My second checkbox!', default=True)],
[sg.Radio('My first Radio! ', "RADIO1", default=True), sg.Radio('My second Radio!', "RADIO1")],
[sg.Multiline(default_text='This is the default Text shoulsd you decide not to type anything',
scale=(2, 10))],
[sg.InputCombo(['Combobox 1', 'Combobox 2'], size=(20, 3)),
sg.Slider(range=(1, 100), orientation='h', size=(35, 20), default_value=85)],
[sg.Listbox(values=['Listbox 1', 'Listbox 2', 'Listbox 3'], size=(30, 6)),
sg.Slider(range=(1, 100), orientation='v', size=(10, 20), default_value=25),
sg.Slider(range=(1, 100), orientation='v', size=(10, 20), default_value=75),
sg.Slider(range=(1, 100), orientation='v', size=(10, 20), default_value=10)],
[sg.Text('_' * 100, size=(70, 1))],
[sg.Text('Choose Source and Destination Folders', size=(35, 1))],
[sg.Text('Source Folder', size=(15, 1), auto_size_text=False, justification='right'), sg.InputText('Source'),
sg.FolderBrowse()],
[sg.Text('Destination Folder', size=(15, 1), auto_size_text=False, justification='right'), sg.InputText('Dest'),
sg.FolderBrowse()],
[sg.Submit(), sg.Cancel(), sg.SimpleButton('Customized', button_color=('white', 'green'))]
]
button, values = form.LayoutAndRead(layout)[3]
Getting Started with PySimpleGUI
External links
For configuring and getting started with PySimpleGUI you can refer to the GitHub project.
For a deeper look into the use of PySimpleGUI you can refer to the PySimpleGUI cookbook.
For the latest new on PySimpleGUI you can refer to the GitHubWiki page.
Compatibility
Python 3 tkinter
RasberryPi (For examples running on a RasberryPi please refer to entries found on the Rasberrypi forums.[6])
This article "PySimpleGUI" is from Wikipedia. The list of its authors can be seen in its historical and/or the page Edithistory:PySimpleGUI. Articles copied from Draft Namespace on Wikipedia could be seen on the Draft Namespace of Wikipedia and not main one.
- ↑ 1.0 1.1 1.2 "PySimpleGui". libraries.io. Retrieved 2018-09-07.
- ↑ 2.0 2.1 2.2 2.3 "PySimpleGUI". PyPI. Retrieved 2018-09-07.
- ↑ 3.0 3.1 "Add GUIs to your programs and scripts easily with PySimpleGUI". Opensource.com. Retrieved 2018-09-07.
- ↑ "A simple yet powerful GUI built on top of tkinter". Python Awesome. 2018-07-19. Retrieved 2018-09-08.
- ↑ "Add GUIs to your programs and scripts easily with PySimpleGUI - PySimpleGUI". pysimplegui.readthedocs.io. Retrieved 2018-09-12.
- ↑ "PySimpleGUI - New package for building custom GUIs in a few lines of code - Page 2 - Raspberry Pi Forums". www.raspberrypi.org. Retrieved 2018-09-08.

