PySimpleGUI is a wrapper that facilitates and speeds up the creation of Python window applications. There are 4 ports, based on the following libraries: tkinter, Qt, WxPython, Remi.
Changing the port eg. from PySimpleGUI (based on tkinter) to PySimpleGUIQt (using Qt) does not require any further code changes! More details can be found >>here<<.
A sample program that collects data from the user and displays the data in a second window:
import PySimpleGUIQt as sg layout = [[sg.Text('Please enter some sample text')], [sg.InputText()], [sg.Submit('Apply'), sg.Cancel('Cancel')]] window = sg.Window('Data source window', layout) event, values = window.Read() window.Close() if event == 'Apply': text_input = values sg.Popup('Text entered:', text_input, title='Data display window')
The first line of the script imports the wrapper module (it must be installed in the system e.g. via pip, as well as the framework that is used by the port – in this case Qt).
The next line defines the layout, which is a list of lists. Each subsequent list defines the next line of the template – the Text element on the first line that writes ‘Please enter some sample text’ , the InputText field in the second, and the Apply and Cancel buttons on the third line.
Then we create a window and assign the previously created layout as the second argument. Pressing any button or closing the window will switch to the window status reading – a tuple consisting of: the event element (e.g. button name or None when the window closing button is pressed) and a dictionary containing keys describing the window input fields and the values entered in these fields is returned.
When the key argument is not given for an input field when creating a layout, by default the dictionary keys are consecutive integer values. In the above example, the text entered, which is saved in the values dictionary as the key value 0, is passed as an element of the string displayed in the popup window (Window displaying data).