PySimpleGUI / PySimpleGUI/PySimpleGUI
*** NEW FEATURE *** The PySimpleGUI PEP8 interface! For those that hate the camel cased methods....
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 13.8k
- Forks
- 1.8k
- PR merge metrics
- No merged PRs in 30d
Description
One "problem" with PySimpleGUI is that it's not PEP8 compliant. When it was originally written, PEP8 wasn't part of my vocabulary. Somehow I missed that chapter. I think it was because I was really learning about classes for the first time (first time having to use them for real).
Through the magic of Python, I'm happy to say that ALL of the interfaces in the Elements and all of the functions you call have a PEP8 equivalent now. Notice that I didn't say replaced.
You can use BOTH the "old", "original recipe" way, or the new PEP8 way. I suppose eventually the old way will need to stop being supported, but that's not going to be for a while as all of the docs need to change again, as well as the Demos, etc.
What does this really mean?
It means you can write:
window.FindElement as window.find_element
Combo.Update as Combo.update
Popup as 'popup'
PopupAutoClose as popup_auto_close
Make sense?
This is in release 4.3.0.1 Unreleased on GitHub. We need some runtime on it before sending to PyPI, although I'm tempted to go straight there with it as not many people run right from the GitHub that I'm aware of. Only if I fix a bug or add a new feature do people tend to grab it.
Anyway, it's there. You can stop grumbling in your head if that's what you've been doing. Strangely, it HAS been only in people's heads. Not since the initial release when CamelCase was also used for named parameters that I have heard a complaint about the method names. Or if I do, it's super rare and not made a huge deal of. It's probably because Qt does this too?
It's fully recognized that if this package is to go further mainstream, it needs to look the part of a Python solution for GUIs. If PySimpleGUI is going to claim to be very-pythonic, then gotta be PEP8 compliant from a users point of view. Internally the code is still a mess however :-)
Oh, finally, you will have to do a second jump to get to the definition of a method if you are debugging in an IDE and are looking up the location of the method. The help system and docs continue to show the old naming conventions. They'll get fixed over time... just not yet.
Design Pattern 2B from the cookbook.... old and new ways
import PySimpleGUI as sg
layout = [[sg.Text('Your typed chars appear here:'), sg.Text('', size=(15,1), key='_OUTPUT_')],
[sg.Input(key='_IN_')],
[sg.Button('Show'), sg.Button('Exit')]]
window = sg.Window('Window Title', layout)
while True: # Event Loop
event, values = window.Read()
print(event, values)
if event is None or event == 'Exit':
break
if event == 'Show':
# Update the "output" element to be the value of "input" element
window.Element('_OUTPUT_').Update(values['_IN_'])
window.Close()
The PEP8 interface way
import PySimpleGUI as sg
layout = [[sg.Text('Your typed chars appear here:'), sg.Text('', size=(15,1), key='_OUTPUT_')],
[sg.Input(key='_IN_')],
[sg.Button('Show'), sg.Button('Exit')]]
window = sg.Window('Window Title', layout)
while True: # Event Loop
event, values = window.read()
print(event, values)
if event in (None, 'Exit'):
break
if event == 'Show':
# Update the "output" element to be the value of "input" element
window.find_element('_OUTPUT_').update(values['_IN_'])
window.close()
And finally, the PEP8 + New FindElement + New Update.
In the 4.2 release the FindElement was replaced by window[key].
Also in the 4.2 release, you can "call Update" by calling the object. Yes, sounds weird but is awesome in reality
This version is only 1 line change different than the above, but wanted to give a complete version every time.
import PySimpleGUI as sg
layout = [[sg.Text('Your typed chars appear here:'), sg.Text('', size=(15,1), key='_OUTPUT_')],
[sg.Input(key='_IN_')],
[sg.Button('Show'), sg.Button('Exit')]]
window = sg.Window('Window Title', layout)
while True: # Event Loop
event, values = window.read()
print(event, values)
if event in (None, 'Exit'):
break
if event == 'Show':
# Update the "output" element to be the value of "input" element
window['_OUTPUT_'](values['_IN_'])
window.close()
None of this is documented in the docs yet as they only came to be today and yesterday I think. It's a blur.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names no files or tests and says the PEP8 interface is already implemented in release 4.3.0.1, while documentation and demos remain to be updated. Start by reviewing the existing docs and Demos for old API examples; done means the relevant examples explain and use the PEP8 equivalents while preserving the legacy compatibility described here.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- developer-experience, documentation
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100