PySimpleGUI – Discussion ”; Previous Next PySimpleGui is an open source, cross-platform GUI library for Python. It aims to provide a uniform API for creating desktop GUIs based on Python’s Tkinter, PySide and WxPython toolkits. PySimpleGUI also has a port for Remi which is useful for building GUIs for the web. PySimpleGui lets you build GUIs quicker than by directly using the libraries it uses. Print Page Previous Next Advertisements ”;
Category: pysimplegui
PySimpleGUI – Quick Guide
PySimpleGUI – Quick Guide ”; Previous Next PySimpleGUI – Introduction Python GUIs for Humans The PySimpleGui project started as a wrapper around TKinter package, which is bundled with Python’s standard library, with the objective to simplify the GUI building process. PySimpleGui subsequently added the ability to design desktop GUIs based on PySide library (which itself ports Qt GUI toolkit, originally written in C++, to Python) and WxPython (which ports another popular GUI toolkit called WxWidgets). These libraries are called PySimpleGUIQt and PySimpleGUIWx respectively. The latest addition to the PySimpleGui family is the PySimpleGUIWeb package which uses the Remi (REMote Interface Library) to construct GUI design that is rendered in a web page. All the packages in the PySimpleGui group follow the similar API, which means the names of GUI elements, their properties and methods are same in all the four packages. As a result, just by replacing the import statement (and keeping the rest of the code unchanged), one can get the corresponding GUI design rendered. This is in fact the most important feature of PySimpleGui. That’s why, it is known as Python GUIs for Humans. Comparison with other GUI Frameworks A Python programmer has a variety of GUI frameworks to choose from, to develop a GUI application. TKinter is the one which is officially included in Python’s standard library. Others, most of them are open source, have to be explicitly installed. Sr.No. Library & Description 1 TkInter Included in Python standard library 2 PyQt Python 3 bindings for the Qt application framework. 3 PySide Qt for Python (formerly known as PySide) offers the official Python bindings for the Qt cross-platform application and UI framework. 4 PySimpleGUI Wraps tkinter, Qt (pyside2), wxPython and Remi (for browser support) in a non-OOP API 5 wxPython Supports Windows/Unix/Mac. Supports Python 2.7 and >=3.4. Wraps & extends the wxWidgets toolchain. 6 PyGObject PyGObject is a Python package which provides bindings for GObject based libraries such as GTK Replacement for PyGtk. 7 PyForms A Python framework to develop GUI application, which promotes modular software design and code reusability with minimal effort. PySimpleGUI – Environment Setup PySimpleGui supports both Python 3.x versions as well as Python 2.7 version. The main port, PySimpleGui doesn’t have any external dependencies, as Tkinter – on which it is based – is a part of Python’s standard library, and hence it needn’t be installed separately. Install it in the current Python3 environment by the PIP installer as follows pip3 install PySimpleGUI To verify if the library is correctly installed, enter the following statement − >>> import PySimpleGUI >>> PySimpleGUI.version ”4.60.1 Released 22-May-2022” In case, the PIP installation doesn’t work, you can download “pysimplegui.py” from the Github repository (https://github.com/PySimpleGUI/PySimpleGUI) and place it in your folder along with the application that is importing it. The pysimplegui.py file has the “main()” function. When called from Python prompt, it generates the following window to affirm that the package is correctly installed. >>> import PySimpleGUI as psg >>> psg.main() Starting up PySimpleGUI Diagnostic & Help System PySimpleGUI long version = 4.60.1 Released 22-May-2022 PySimpleGUI Version 4.60.1 tcl ver = 8.6 tkinter version = 8.6 Python Version 3.6.8 (tags/v3.6.8:3c6b436a57, Dec 24 2018, 00:16:47) [MSC v.1916 64 bit (AMD64)] tcl detailed version = 8.6.6 PySimpleGUI.py location F:python36libsitepackagesPySimpleGUIPySimpleGUI.py The GUI window appears as below: If you are using Python3 version earlier than 3.4, you may need to install the “typing” module since it is not shipped in the corresponding standard library pip3 install typing For Python 2.7, change the name to PySimpleGUI27. pip3 install PySimpleGUI27 You may need to also install “future” for version 2.7 pip3 install future However, it is important to note that Python Software Foundation doesn’t officially support Python 2.x branches. PySimpleGUI – Hello World First Window using PySimpleGUI To check whether PySimpleGUI along with its dependencies are properly installed, enter the following code and save it as “hello.py”, using any Python-aware editor. import PySimpleGUI as psg layout = [[psg.Text(text=”Hello World”, font=(”Arial Bold”, 20), size=20, expand_x=True, justification=”center”)], ] window = psg.Window(”HelloWorld”, layout, size=(715,250)) while True: event, values = window.read() print(event, values) if event in (None, ”Exit”): break window.close() The above code constructs a window with a Text element (equivalent of a Label in TKinter) and displays the “Hello World” message placed centrally across the width of the window. Run this program from the command terminal as − Python hello.py The output generated by the program should be similar to the one displayed below − Equivalent Tkinter Code To obtain similar output using pure Tkinter code, we would require the following Python script − from tkinter import * window=Tk() lbl=Label(window, text=”Hello World”, fg=”white”, bg=”#64778D”, font=(“Arial Bold”, 20)) lbl.place(x=300, y=15) window.title(”HelloWorld Tk”) window[”bg”]=”#64778D” window.geometry(“715×250+10+10″) window.mainloop() All other functionalities remain same, except we use the serve() function off waitress module to start the WSGI server. On visiting the ”/” route in the browser after running the program, the Hello World message is displayed as before. Instead of a function, a callable class can also be used as a View. A callable class is the one which overrides the __call__() method. from pyramid.response import Response class MyView(object): def __init__(self, request): self.request = request def __call__(self): return Response(”hello world”) PySimpleGUIQt The object model of PySimpleGUI API has been made compatible with the widgets as defined in PySide2 package (which is the Python port for Qt graphics toolkit). The Qt version of PySimpleGui is called PySimpleGUIQt. It can be similarly installed with following PIP command − pip3 install PySimpleGUIQt
PySimpleGUI – Useful Resources ”; Previous Next The following resources contain additional information on PySimpleGUI. Please use them to get more in-depth knowledge on this. Useful Video Courses Python Flask and SQLAlchemy ORM 22 Lectures 1.5 hours Jack Chan More Detail Python and Elixir Programming Bundle Course 81 Lectures 9.5 hours Pranjal Srivastava More Detail TKinter Course – Build Python GUI Apps 49 Lectures 4 hours John Elder More Detail A Beginner”s Guide to Python and Data Science 81 Lectures 8.5 hours Datai Team Academy More Detail Deploy Face Recognition Project With Python, Django, And Machine Learning Best Seller 93 Lectures 6.5 hours Srikanth Guskra More Detail Professional Python Web Development with Flask 80 Lectures 12 hours Stone River ELearning More Detail Print Page Previous Next Advertisements ”;
PySimpleGUI – Working with PIL ”; Previous Next Python Imaging Library is a free, cross-platform and open-source library for the Python programming language that has the functionality for opening, manipulating, and saving many different image file formats. To install it, use the PIP command as follows − pip3 install pillow In the following example, we obtain the byte value of the PNG image with PIL function and display the same in Image element on a PySimpleGUI window. import PySimpleGUI as sg import PIL.Image import io import base64 def convert_to_bytes(file_or_bytes, resize=None): img = PIL.Image.open(file_or_bytes) with io.BytesIO() as bio: img.save(bio, format=”PNG”) del img return bio.getvalue() imgdata = convert_to_bytes(“PySimpleGUI_logo.png”) layout = [[sg.Image(key=”-IMAGE-”, data=imgdata)]] window = sg.Window(”PIL based Image Viewer”, layout,resizable=True) while True: event, values = window.read() if event == sg.WIN_CLOSED: break window.close() It will produce the following output window − Print Page Previous Next Advertisements ”;
PySimpleGUI – Settings
PySimpleGUI – Settings ”; Previous Next Global Settings Global settings are the application settings available application wide. These settings control the various properties of the Element class to be applied to all the Elements in the application. These settings work in hierarchical manner. The global settings are overridden if those settings are given different value for a window. In turn the settings defined in Window object are given different value for a specific element. For example, if the font size is set to 16 globally, the text of all elements is displayed accordingly. However, if a specific Text or Input element with Font property with size other than 16 is defined in the layout, it will change the appearance accordingly. The function set_options is used to change settings that will apply globally. If it”s a setting that applies to Windows, then that setting will apply not only to Windows that you create, but also to popup Windows. import PySimpleGUI as sg sg.set_options(font=(”Arial Bold”, 16)) User Settings “User settings” is a dictionary that is automatically written to your hard drive. User settings are stored in a Python dictionary which is saved to and loaded from the disk. Individual settings are thus keys into a dictionary. List of user setting functions − Sr.No. Function & Description 1 user_settings Returns settings as a dictionary 2 user_settings_delete_entry Deletes a setting 3 user_settings_delete_filename Deletes the settings file 4 user_settings_file_exists Returns True if settings file specified exists 5 user_settings_filename Returns full path and filename of settings file 6 user_settings_get_entry Returns value for a setting. If no setting found, then specified default value is returned 7 user_settings_load Loads dictionary from the settings file. 8 user_settings_save Saves settings to current or newly specified file. 9 user_settings_set_entry Sets an entry to a particular value 10 user_settings_write_new_dictionary Writes a specified dictionary to settings file Create the User Settings object. settings = sg.UserSettings() Use the dictionary-style [ ] syntax to read a setting. If the item”s name is ”- item-”, then reading the value is achieved by writing item_value = settings[”-item-”] Following sttement is used to Write the setting. settings[”-item-”] = new_value To delete an item, again the dictionary style syntax is used. del settings[”-item-”] You can also call the delete_entry method to delete the entry. settings.delete_entry(”-item-”) The following simple program demonstrates load/saving of user settings import PySimpleGUI as sg import json sg.set_options(font=(”Arial Bold”, 16)) layout = [ [sg.Text(”Settings”, justification=”left”)], [sg.Text(”User name”, size=(10, 1), expand_x=True), sg.Input(key=”-USER-”)], [sg.Text(”email ID”, size=(10, 1), expand_x=True), sg.Input(key=”-ID-”)], [sg.Text(”Role”, size=(10, 1), expand_x=True), sg.Input(key=”-ROLE-”)], [sg.Button(“LOAD”), sg.Button(”SAVE”), sg.Button(”Exit”)] ] window = sg.Window(”User Settings Demo”, layout, size=(715, 200)) # Event Loop while True: event, values = window.read() if event in (sg.WIN_CLOSED, ”Exit”): break if event == ”LOAD”: f = open(“settings.txt”, ”r”) settings = json.load(f) window[”-USER-”].update(value=settings[”-USER-”]) window[”-ID-”].update(value=settings[”-ID-”]) window[”-ROLE-”].update(value=settings[”-ROLE-”]) if event == ”SAVE”: settings = {”-USER-”: values[”-USER-”], ”-ID-”: values[”-ID-”], ”-ROLE-”: values[”-ROLE-”]} f = open(“settings.txt”, ”w”) json.dump(settings, f) f.close() window.close() Enter the data in the input boxes and click the “Save” button. A JSON file will be saved. To load the previously saved settings, click the “Load” button. Print Page Previous Next Advertisements ”;
PySimpleGUI – Events
PySimpleGUI – Events ”; Previous Next Any GUI application is event driven, having the ability to respond to the various possible events occurring on the GUI elements. In PySimpleGUI, the event handling is done inside an infinite loop below the constitution of GUI design, continuously checking whether an event occurs and perform the actions based on the event. There are two types of events − Window events, and Element events. The window events are enabled by default, and include the button events (occur when any button is clicked) and the event of the “X” button on the titlebar clicked. The element events are not enabled by default. Element-specific events can be detected only when the “enable_events” parameter is set to True when an element is created. Window Closed Event The infinite event loop that makes the PySimpleGUI window persistent, is terminated when the user presses the “X” button, or the close() method of Window class is executed. The standard way of terminating the loop is as follows − import PySimpleGUI as psg … while True: … if event == psg.WIN_CLOSED: break … window.close() The Widow class also emits an “enable_close_attempted_event” if this parameter is set to True. It is a good practice to call yes-no popup when it is detected inside the loop. window = psg.Window(”Calculator”, layout, enable_close_attempted_event=True) while True: event, values = window.read() print(event, values) if event == “Add”: result = int(values[”-FIRST-”]) + int(values[”-SECOND-”]) if event == “Sub”: result = int(values[”-FIRST-”]) – int(values[”-SECOND-”]) window[”-OUT-”].update(result) if event == psg.WINDOW_CLOSE_ATTEMPTED_EVENT and psg.popup_yes_no(”Do you really want to exit?”) == ”Yes”: break if event == psg.WIN_CLOSED or event == ”Exit”: break In this case, as the “X” button is pressed, the Popup with Yes/No button appears and the program exits when the “Yes” button is clicked. It will produce the following output window − The event value also returns the “-WINDOW CLOSE ATTEMPTED-” value. -WINDOW CLOSE ATTEMPTED- {”-FIRST-”: ”200”, ”-SECOND-”: ”300”} Button Events The button click event is enabled by default. To disable, use “Button.update(disabled=True)”. You can also set “enable_events=True” in Button’s constructor, it will enable the Button Modified event. This event is triggered when something ”writes” to a button. When we read the contents of the window (using “window.read()”), the button value will be either its caption (if key is not set) or key if it is set. In the above example, since the key parameter is not set on the Add and Sub buttons, their captions are returned when the window is read. Add {”-FIRST-”: ”200”, ”-SECOND-”: ”300”} Add key parameters to Add and Sub buttons in the program. import PySimpleGUI as psg layout = [ [psg.Text(”Enter a num: ”), psg.Input(key=”-FIRST-”)], [psg.Text(”Enter a num: ”), psg.Input(key=”-SECOND-”)], [psg.Text(”Result : ”), psg.Text(key=”-OUT-”)], [psg.Button(“Add”, key=”-ADD-”), psg.Button(“Sub”, key=”- SUB-”), psg.Exit()], ] window = psg.Window(”Calculator”, layout) while True: event, values = window.read() print(event, values) if event == “-ADD-“: result = int(values[”-FIRST-”]) + int(values[”-SECOND-”]) if event == “-SUB-“: result = int(values[”-FIRST-”]) – int(values[”-SECOND-”]) window[”-OUT-”].update(result) if event == psg.WIN_CLOSED or event == ”Exit”: break window.close() The tuple returned by the read() method will now show the key of button pressed. -ADD- {”-FIRST-”: ”200”, ”-SECOND-”: ”300”} Events of Other Elements Many of the elements emit events when some type of user interaction takes place. For example, when a slider is moved, or an item from the list is selected on or a radio button is clicked on. Unlike Button or Window, these events are not enabled by default. To enable events for an Element, set the parameter “enable_events=True”. The following table shows the elements and the events generated by them. Name Events InputText any key pressed Combo item selected Listbox selection changed Radio selection changed Checkbox selection changed Spinner new item selected Multiline any key pressed Text Clicked Status Bar Clicked Graph Clicked Graph Dragged Graph drag ended (mouse up) TabGroup tab clicked Slider slider moved Table row selected Tree node selected ButtonMenu menu item chosen Right click menu menu item chosen Print Page Previous Next Advertisements ”;
PySimpleGUI – Matplotlib Integration ”; Previous Next When Matplotlib is used from Python shell, the plots are displayed in a default window. The backend_tkagg module is useful for embedding plots in Tkinter. The Canvas element in PySimpleGUI has TKCanvas method that returns original TKinter”s Canvas object. It is given to the FigureCanvasTkAgg() function in the backend_tkagg module to draw the figure. First, we need to create the figure object using the Figure() class and a plot to it. We shall draw a simple plot showing sine wave. fig = matplotlib.figure.Figure(figsize=(5, 4), dpi=100) t = np.arange(0, 3, .01) fig.add_subplot(111).plot(t, 2 * np.sin(2 * np.pi * t)) Define a function to draw the matplotlib figure object on the canvas def draw_figure(canvas, figure): figure_canvas_agg = FigureCanvasTkAgg(figure, canvas) figure_canvas_agg.draw() figure_canvas_agg.get_tk_widget().pack(side=”top”, fill=”both”, expand=1) return figure_canvas_agg Obtain the Canvas from PySimpleGUI.Canvas object by calling its TkCanvas property. layout = [ [psg.Text(”Plot test”)], [psg.Canvas(key=”-CANVAS-”)], [psg.Button(”Ok”)] ] Draw the figure by calling the above function. Pass the Canvas object and fifure object to it. fig_canvas_agg = draw_figure(window[”-CANVAS-”].TKCanvas, fig) Example: Draw a Sinewave Line graph The complete code is given below − import matplotlib.pyplot as plt import numpy as np from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg import PySimpleGUI as sg import matplotlib matplotlib.use(”TkAgg”) fig = matplotlib.figure.Figure(figsize=(5, 4), dpi=100) t = np.arange(0, 3, .01) fig.add_subplot(111).plot(t, 2 * np.sin(2 * np.pi * t)) def draw_figure(canvas, figure): tkcanvas = FigureCanvasTkAgg(figure, canvas) tkcanvas.draw() tkcanvas.get_tk_widget().pack(side=”top”, fill=”both”, expand=1) return tkcanvas layout = [[sg.Text(”Plot test”)], [sg.Canvas(key=”-CANVAS-”)], [sg.Button(”Ok”)]] window = sg.Window(”Matplotlib In PySimpleGUI”, layout, size=(715, 500), finalize=True, element_justification=”center”, font=”Helvetica 18”) # add the plot to the window tkcanvas = draw_figure(window[”-CANVAS-”].TKCanvas, fig) event, values = window.read() window.close() The generated graph is as follows − Print Page Previous Next Advertisements ”;
PySimpleGUI – Hello World
PySimpleGUI – Hello World ”; Previous Next First Window using PySimpleGUI To check whether PySimpleGUI along with its dependencies are properly installed, enter the following code and save it as “hello.py”, using any Python-aware editor. import PySimpleGUI as psg layout = [[psg.Text(text=”Hello World”, font=(”Arial Bold”, 20), size=20, expand_x=True, justification=”center”)], ] window = psg.Window(”HelloWorld”, layout, size=(715,250)) while True: event, values = window.read() print(event, values) if event in (None, ”Exit”): break window.close() The above code constructs a window with a Text element (equivalent of a Label in TKinter) and displays the “Hello World” message placed centrally across the width of the window. Run this program from the command terminal as − Python hello.py The output generated by the program should be similar to the one displayed below − Equivalent Tkinter Code To obtain similar output using pure Tkinter code, we would require the following Python script − from tkinter import * window=Tk() lbl=Label(window, text=”Hello World”, fg=”white”, bg=”#64778D”, font=(“Arial Bold”, 20)) lbl.place(x=300, y=15) window.title(”HelloWorld Tk”) window[”bg”]=”#64778D” window.geometry(“715×250+10+10″) window.mainloop() All other functionalities remain same, except we use the serve() function off waitress module to start the WSGI server. On visiting the ”/” route in the browser after running the program, the Hello World message is displayed as before. Instead of a function, a callable class can also be used as a View. A callable class is the one which overrides the __call__() method. from pyramid.response import Response class MyView(object): def __init__(self, request): self.request = request def __call__(self): return Response(”hello world”) PySimpleGUIQt The object model of PySimpleGUI API has been made compatible with the widgets as defined in PySide2 package (which is the Python port for Qt graphics toolkit). The Qt version of PySimpleGui is called PySimpleGUIQt. It can be similarly installed with following PIP command − pip3 install PySimpleGUIQt Since this package depends on PySide2, the same will also be installed. >>> import PySide2 >>> PySide2.__version__ ”5.15.2.1” >>> import PySimpleGUIQt >>> PySimpleGUIQt.version ”0.35.0 Released 6-Jun-2020” As mentioned earlier, the most important feature of PySimpleGui projects is that the code written for one package is completely compatible with the other. Hence, the hello.py program used earlier can be used as it is for the Qt version. The only change needed is import PySimpleGUIQt instead of PySimpleGui. import PySimpleGUIQt as psg layout = [[psg.Text(text=”Hello World”, font=(”Arial Bold”, 20), justification=”center”)], ] window = psg.Window(”HelloWorldQt”, layout, size=(715,250)) while True: event, values = window.read() print(event, values) if event in (None, ”Exit”): break window.close() The output is fairly similar. Equivalent PySide2 Code The pure PySide2 code to achieve the same result is as follows − import sys from PySide2.QtCore import * from PySide2.QtGui import * from PySide2.QtWidgets import * def window(): app = QApplication(sys.argv) w = QWidget() w.setStyleSheet(“background-color: #64778D;”) b = QLabel(w) b.setText(“Hello World!”) b.setFont(QFont(”Arial Bold”, 20)) b.setAlignment(Qt.AlignCenter) b.setStyleSheet(“color: white;”) b.setGeometry(100, 100, 715, 250) b.move(50, 20) w.setWindowTitle(“HelloWorldQt”) w.show() sys.exit(app.exec_()) if __name__ == ”__main__”: window() It will produce the same output window. PySimpleGUIWx This module encapsulates the functionality of GUI widgets as defined in WxPython toolkit. WxPython is a Python port for the widely used WxWidgets library originally written in C++. Obviously, PySimpleGUIWx depends on WxPython package, and hence the latter will get automatically installed by the following PIP command − pip3 install PySimpleGUIWx To confirm that both PySimpleGUIWx and WxPython are properly installed, enter following statements in Python terminal. >>> import PySimpleGUIWx >>> PySimpleGUIWx.version ”0.17.1 Released 7-Jun-2020” >>> import wx >>> wx.__version__ ”4.0.7” Not much of change is required in the “hello.py” script. We need to just replace PySimpleGUI with PySimpleGUIWx module in the “import” statement. import PySimpleGUIWx as psg layout = [[psg.Text(text=”Hello World”, font=(”Arial Bold”, 20), size=(500, 5), justification=”center”)], ] window = psg.Window(”HelloWorldWx”, layout, size=(715, 250)) while True: event, values = window.read() print(event, values) if event in (None, ”Exit”): break window.close() It will produce the following output: Note that you’ll need a little more complex code to obtain the similar output with pure WxPython code as follows − import wx app = wx.App() window = wx.Frame(None, title=”WxPython”, size=(715, 250)) panel = wx.Panel(window) panel.SetBackgroundColour((100, 119, 141)) label = wx.StaticText(panel, -1, style=wx.ALIGN_CENTER) label.SetLabel(“Hello World”) label.SetForegroundColour((255, 255, 255)) font = wx.Font() font.SetFaceName(“Arial Bold”) font.SetPointSize(30) label.SetFont(font) window.Show(True) app.MainLoop() It will display a top level window with a text label having Hello World as the caption. PySimpleGUIWeb Remi (REMote Interface) is a GUI library for Python applications that are rendered in a web browser. PySimpleGUIWeb package ports the original PySimpleGui library to Remi so that its apps can be run in a browser. Following PIP command installs both PySimpleGUIWeb and Remi in the current Python environment − pip3 install PySimpleGUIWeb Check for their proper installation before writing an app. >>> import PySimpleGUIWeb >>> PySimpleGUIWeb.version ”0.39.0 Released 6-Jun-2020” Following script is the PySimpleGUIWeb version of the original Hello World program. import PySimpleGUIWeb as psg layout = [[psg.Text(text=”Hello World”, font=(”Arial Bold”, 20), justification=”center”)]] window = psg.Window(”HelloWorldWeb”, layout) while True: event, values = window.read() print(event, values) if event in (None, ”Exit”): break window.close() To obtain similar output using pure Remi library’s functionality is a little complex, as the following code shows: import remi.gui as gui from remi import start, App class HelloWeb(App): def __init__(self, *args): super(HelloWeb, self).__init__(*args) def main(self): wid = gui.VBox(style={“background-color”: “#64778D”}) self.lbl = gui.Label(”Hello World”, width=”100%”, height=”100%”, style={ “color”:”white”, “text-align”: “center”, “font-family”: “Arial Bold”, “font-size”: “20px”} ) wid.append(self.lbl) return wid if __name__ == “__main__”: start(HelloWeb, debug=True, address=”0.0.0.0”, port=0) When we run these programs, the Remi server starts, a browser window automatically opens and the Hello World message is displayed. Here we have seen the Hello World program written in the PySimpleGUI, PySimpleGUIQt, PySimpleGUIWx and PySimpleGUIWeb libraries. We can see that
PySimpleGUI – Introduction
PySimpleGUI – Introduction ”; Previous Next Python GUIs for Humans The PySimpleGui project started as a wrapper around TKinter package, which is bundled with Python’s standard library, with the objective to simplify the GUI building process. PySimpleGui subsequently added the ability to design desktop GUIs based on PySide library (which itself ports Qt GUI toolkit, originally written in C++, to Python) and WxPython (which ports another popular GUI toolkit called WxWidgets). These libraries are called PySimpleGUIQt and PySimpleGUIWx respectively. The latest addition to the PySimpleGui family is the PySimpleGUIWeb package which uses the Remi (REMote Interface Library) to construct GUI design that is rendered in a web page. All the packages in the PySimpleGui group follow the similar API, which means the names of GUI elements, their properties and methods are same in all the four packages. As a result, just by replacing the import statement (and keeping the rest of the code unchanged), one can get the corresponding GUI design rendered. This is in fact the most important feature of PySimpleGui. That’s why, it is known as Python GUIs for Humans. Comparison with other GUI Frameworks A Python programmer has a variety of GUI frameworks to choose from, to develop a GUI application. TKinter is the one which is officially included in Python’s standard library. Others, most of them are open source, have to be explicitly installed. Sr.No. Library & Description 1 TkInter Included in Python standard library 2 PyQt Python 3 bindings for the Qt application framework. 3 PySide Qt for Python (formerly known as PySide) offers the official Python bindings for the Qt cross-platform application and UI framework. 4 PySimpleGUI Wraps tkinter, Qt (pyside2), wxPython and Remi (for browser support) in a non-OOP API 5 wxPython Supports Windows/Unix/Mac. Supports Python 2.7 and >=3.4. Wraps & extends the wxWidgets toolchain. 6 PyGObject PyGObject is a Python package which provides bindings for GObject based libraries such as GTK Replacement for PyGtk. 7 PyForms A Python framework to develop GUI application, which promotes modular software design and code reusability with minimal effort. Print Page Previous Next Advertisements ”;
PySimpleGUI – Environment Setup ”; Previous Next PySimpleGui supports both Python 3.x versions as well as Python 2.7 version. The main port, PySimpleGui doesn’t have any external dependencies, as Tkinter – on which it is based – is a part of Python’s standard library, and hence it needn’t be installed separately. Install it in the current Python3 environment by the PIP installer as follows pip3 install PySimpleGUI To verify if the library is correctly installed, enter the following statement − >>> import PySimpleGUI >>> PySimpleGUI.version ”4.60.1 Released 22-May-2022” In case, the PIP installation doesn’t work, you can download “pysimplegui.py” from the Github repository (https://github.com/PySimpleGUI/PySimpleGUI) and place it in your folder along with the application that is importing it. The pysimplegui.py file has the “main()” function. When called from Python prompt, it generates the following window to affirm that the package is correctly installed. >>> import PySimpleGUI as psg >>> psg.main() Starting up PySimpleGUI Diagnostic & Help System PySimpleGUI long version = 4.60.1 Released 22-May-2022 PySimpleGUI Version 4.60.1 tcl ver = 8.6 tkinter version = 8.6 Python Version 3.6.8 (tags/v3.6.8:3c6b436a57, Dec 24 2018, 00:16:47) [MSC v.1916 64 bit (AMD64)] tcl detailed version = 8.6.6 PySimpleGUI.py location F:python36libsitepackagesPySimpleGUIPySimpleGUI.py The GUI window appears as below: If you are using Python3 version earlier than 3.4, you may need to install the “typing” module since it is not shipped in the corresponding standard library pip3 install typing For Python 2.7, change the name to PySimpleGUI27. pip3 install PySimpleGUI27 You may need to also install “future” for version 2.7 pip3 install future However, it is important to note that Python Software Foundation doesn’t officially support Python 2.x branches. Print Page Previous Next Advertisements ”;