You can edit almost every page by Creating an account and confirming your email.

PySimpleGUI: Difference between revisions

From EverybodyWiki Bios & Wiki
m Moved page from Draft:PySimpleGUI
WikiMasterBot2 (talk | contribs)
m replace single = by ==
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{AFC submission|d|nn|u=Kgcastellon|ns=118|decliner=Robert McClenon|declinets=20180905040927|reason2=v|ts=20180905035932}} <!-- Do not remove this line! -->
{{AFC submission|d|nn|u=Kgcastellon|ns=118|decliner=Newslinger|declinets=20181225120028|ts=20181219162648}} <!-- Do not remove this line! -->
{{AFC submission|d|nn|u=Kgcastellon|ns=118|decliner=Robert McClenon|declinets=20180905040927|reason2=v|small=yes|ts=20180905035932}} <!-- Do not remove this line! -->
 
{{AFC comment|1=The article doesn't cite any [[WP:SIGCOV|significant coverage]] from [[WP:IS|independent sources]] that are also [[WP:RS|reliable]]. If there are no such sources available, then it's best to wait until these sources emerge before submitting the draft again. —&nbsp;'''''[[User:Newslinger|<span style="color:#536267;">Newslinger</span>]]'''&nbsp;<small>[[User talk:Newslinger#top|<span style="color:#708090;">talk</span>]]</small>'' 12:00, 25 December 2018 (UTC)}}


{{AFC comment|1=This draft has no independent references.  It does not establish [[WP:NSOFTWARE|software notability]] or [[WP:GNG|general notability]].
{{AFC comment|1=This draft has no independent references.  It does not establish [[WP:NSOFTWARE|software notability]] or [[WP:GNG|general notability]].
Line 23: Line 26:
| discontinued = <!-- Set to yes if software is discontinued, otherwise omit. -->
| discontinued = <!-- Set to yes if software is discontinued, otherwise omit. -->
| ver layout = <!-- simple (default) or stacked -->
| ver layout = <!-- simple (default) or stacked -->
| latest release version = 3.11.0<ref name=":1">{{Cite web|url=https://pypi.org/project/PySimpleGUI/|title=PySimpleGUI|website=PyPI|language=en|access-date=2018-09-07}}</ref>
| latest release version = 3.20.0<ref name=":1">{{Cite web|url=https://pypi.org/project/PySimpleGUI/|title=PySimpleGUI|website=PyPI|language=en|access-date=2018-09-07}}</ref>
| latest release date = {{Start date and age|2018|10|28|df=yes}}<ref name=":0" />
| latest release date = {{Start date and age|2018|12|18|df=yes}}<ref name=":0" />
| latest preview version =  
| latest preview version =  
| latest preview date = <!-- {{Start date and age|YYYY|MM|DD|df=yes/no}} -->
| latest preview date = <!-- {{Start date and age|YYYY|MM|DD|df=yes/no}} -->
Line 43: Line 46:
}}
}}


= PySimpleGUI =
== PySimpleGUI ==
[https://pypi.org/project/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 [https://github.com/robertlugg/easygui EasyGUI] and [https://github.com/JorjMcKie/wxsimpleGUI WxSimpleGUI], and adds the ability to define custom layouts.<ref name=":1" />
[https://pypi.org/project/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 [https://github.com/robertlugg/easygui EasyGUI] and [https://github.com/JorjMcKie/wxsimpleGUI WxSimpleGUI], and adds the ability to define custom layouts.<ref name=":1" />


Line 50: Line 53:


== Background ==
== 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.<ref name=":0" /> The PySimpleGUI package is focused on the developer, allowing them to create a custom GUI with as concise code as possible.
Launched in July, 2018, PySimpleGUI sought a solution to streamline the Python GUI development efforts and move users from the command line to a windowed / GUI experience.<ref name=":0" /> The PySimpleGUI package is focused on the developer, allowing them to create a custom GUI with as concise code as possible.


== Features ==
== Features ==
Line 57: Line 60:
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.  
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.  


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().
A second shortcut mechanism is 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().
{| class="wikitable mw-collapsible"
{| class="wikitable mw-collapsible"
|+Examples of UI elements, button-shortcuts, and element abbreviations
|+Examples of UI elements, button-shortcuts, and element abbreviations
Line 136: Line 139:
|}
|}


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.<ref name=":3">{{Cite news|url=https://opensource.com/article/18/8/pysimplegui|title=Add GUIs to your programs and scripts easily with PySimpleGUI|work=Opensource.com|access-date=2018-09-07|language=en}}</ref> For full list of features and how to implement them please refer to the [https://pysimplegui.readthedocs.io/en/latest/cookbook/ CookBook].
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.<ref name=":3">{{Cite news|url=https://opensource.com/article/18/8/pysimplegui|title=Add GUIs to your programs and scripts easily with PySimpleGUI|work=Opensource.com|access-date=2018-09-07|language=en}}</ref> For full list of features and how to implement them please refer to the PySimpleGUI [https://pysimplegui.readthedocs.io/en/latest/cookbook/ CookBook].


== Design Goals ==
== Design Goals ==
Line 157: Line 160:


=== Hello World  ===
=== Hello World  ===
<code>'''<nowiki/><nowiki/>'''</code><code>'''<nowiki/><nowiki/>'''</code>
<code>'''import''' PySimpleGUI '''as''' sg</code><br><code>layout = [[sg.'''Text'''('''<nowiki/>'Hello World!'<nowiki/>''')],</code><br><code>         [sg.'''Ok'''()]]</code><br><code>window = sg.'''Window'''('''<nowiki/>'Wikipedia Window'<nowiki/>''').'''Layout'''(layout)</code><br><code>event, data = window.'''Read'''()</code><code>'''<nowiki/><nowiki/>'''</code><code>'''<nowiki/><nowiki/>'''</code><code>'''<nowiki/><nowiki/>'''</code><code>'''<nowiki/><nowiki/>'''</code>[[File:PySimpleGUI HelloWorld.jpg|thumb|This is the built PySimpleGUI Hello World example.|alt=|none]]<br />
<code>'''import''' PySimpleGUI '''as''' sg</code><br><code>layout = [[sg.'''Text'''('''<nowiki/>'Hello World!'<nowiki/>''')],</code><br><code>         [sg.'''Ok'''()]]</code><br><code>window = sg.'''Window'''('''<nowiki/>'Wikipedia Window'<nowiki/>''').'''Layout'''(layout)</code><br><code>event, data = window.'''Read'''()</code>
 
[[File:PySimpleGUI HelloWorld.jpg|thumb|This is the built PySimpleGUI Hello World example.|alt=|none]]Here is a simple form with 3 text input fields and a couple of buttons.<ref>{{Cite web|url=https://pysimplegui.readthedocs.io/en/latest/tutorial/|title=Add GUIs to your programs and scripts easily with PySimpleGUI - PySimpleGUI|website=pysimplegui.readthedocs.io|language=en|access-date=2018-09-12}}</ref><br>
 
<code>1  import PySimpleGUI as sg # Very basic form. Return values as a list</code><br><code>2  form = sg.FlexForm('Simple data entry form')  # begin with a blank form</code><br><code>3  layout = [</code><br><code>4      [sg.Text('Please enter your Name, Address, Phone')],</code><br><code>5      [sg.Text('Name', size=(15, 1)), sg.InputText('name')],</code><br><code>6      [sg.Text('Address', size=(15, 1)), sg.InputText('address')],</code><br><code>7      [sg.Text('Phone', size=(15, 1)), sg.InputText('phone')],</code><br><code>8      [sg.Submit(), sg.Cancel()]</code><br><code>9  ]</code><br><code>10 button, values = form.LayoutAndRead(layout)</code><br><code>11 print(button, values[0], values[1], values[2])</code><br>
 
* 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.
 
[[File:Multi-Form_Widget_example.jpg]]
 
Here is the code that produced the above screenshot.
<code>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)</code><ref name=":3" />
== Getting Started with PySimpleGUI ==
== Getting Started with PySimpleGUI ==


Line 216: Line 167:


For a deeper look into the use of PySimpleGUI you can refer to the [https://pysimplegui.readthedocs.io/en/latest/cookbook/ PySimpleGUI cookbook].
For a deeper look into the use of PySimpleGUI you can refer to the [https://pysimplegui.readthedocs.io/en/latest/cookbook/ PySimpleGUI cookbook].
For a lower level look under the hood of PySimpleGUI refer to this explanation by the developer.<ref>{{Cite web|url=https://www.reddit.com/r/Python/comments/a1mj0p/pysimplegui_under_the_hood/|title=PySimpleGui under the hood|last=|first=|date=|website=|archive-url=|archive-date=|access-date=}}</ref>


=== Compatibility ===
=== Compatibility ===
Python 2.7 tkinter
* Python 2.7 tkinter
 
* Python 3 tkinter
Python 3 tkinter
* [[Qt (software)|Qt]]
 
* [[Kivy (framework)|Kivy]] (coming soon)
[[Rasberry Pi|RasberryPi]] (For examples running on a RasberryPi please refer to entries found on the [https://duckduckgo.com/?q=pysimplegui&sites=raspberrypi.org%2Fforums&HTTPS=1&kj=%23c51a4a&ia=web Rasberrypi forums].<ref>{{Cite web|url=https://www.raspberrypi.org/forums/viewtopic.php?t=219201&start=25|title=PySimpleGUI - New package for building custom GUIs in a few lines of code - Page 2 - Raspberry Pi Forums|website=www.raspberrypi.org|language=en-gb|access-date=2018-09-08}}</ref>)
* [[WxPython]] (coming soon)
 
* [[Rasberry Pi|RasberryPi]] (For examples running on a RasberryPi please refer to entries found on the [https://duckduckgo.com/?q=pysimplegui&sites=raspberrypi.org%2Fforums&HTTPS=1&kj=%23c51a4a&ia=web Rasberrypi forums].<ref>{{Cite web|url=https://www.raspberrypi.org/forums/viewtopic.php?t=219201&start=25|title=PySimpleGUI - New package for building custom GUIs in a few lines of code - Page 2 - Raspberry Pi Forums|website=www.raspberrypi.org|language=en-gb|access-date=2018-09-08}}</ref>)
[[Microsoft Windows|Windows]]
* [[Microsoft Windows|Windows]]
 
* [[MacOS|Mac]]
[[MacOS|Mac]]
* [[Linux]]
 
* [[PyPy|PyPy3]]
[[Linux]]


[[PyPy|PyPy3]]
== References ==
{{reflist}}
{{⚠️🚨COPIED from EverybodyWiki ❗❕⚠️😡😤Please respect Licence CC-BY-SA ❗}}
{{Source Wikipedia}}
{{Source Wikipedia}}

Latest revision as of 11:17, 15 January 2025






PySimpleGUI
Developer(s)M. Barnett
Initial release11 July 2018; 7 years ago (2018-07-11)[1]
Stable release
3.20.0[2] / 18 December 2018; 7 years ago (2018-12-18)[1]
Repositorygithub.com/MikeTheWatchGuy/PySimpleGUI
Written inPython
Engine
    Operating systemCross-Platform
    LicenseGNU Lesser General Public License (LGPLV3+)
    Websitepypi.org/project/PySimpleGUI/

    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, PySimpleGUI 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”.

    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.

    A second shortcut mechanism is 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().

    Examples of UI elements, button-shortcuts, and element abbreviations
    UI elements Button-Shortcuts Element abbreviations
    Checkbox

    Column

    FileBrowse

    Image

    InputCombo

    InputText

    Listbox

    Multiline

    Output

    ProgressBar

    Radio

    ReadFormButton

    RealtimeButton

    SimpleButton

    Slider

    Spin

    Text

    FolderBrowse

    Cancel

    Exit

    FileBrowse

    FileSaveAs

    FolderBrowse

    No

    OK

    Ok

    Quit

    ReadFormButton

    RealtimeButton

    Save

    SimpleButton

    Submit

    Yes

    T = Text

    Txt = Text

    In = InputText

    Input = IntputText

    Combo = InputCombo

    DropDown = InputCombo

    Drop = InputCombo

    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 PySimpleGUI 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
    layout = [[sg.Text('Hello World!')],
             [sg.Ok()]]
    window = sg.Window('Wikipedia Window').Layout(layout)
    event, data = window.Read()

    This is the built PySimpleGUI Hello World example.


    Getting Started with PySimpleGUI

    External links

    For the latest news, 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 a lower level look under the hood of PySimpleGUI refer to this explanation by the developer.[5]

    Compatibility

    References

    1. 1.0 1.1 1.2 "PySimpleGui". libraries.io. Retrieved 2018-09-07.
    2. 2.0 2.1 2.2 2.3 "PySimpleGUI". PyPI. Retrieved 2018-09-07.
    3. "Add GUIs to your programs and scripts easily with PySimpleGUI". Opensource.com. Retrieved 2018-09-07.
    4. "A simple yet powerful GUI built on top of tkinter". Python Awesome. 2018-07-19. Retrieved 2018-09-08.
    5. "PySimpleGui under the hood".
    6. "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.


    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.