I didn't want to pollute the global environment, so I decided to create a virtual environment with venv
and work there.
Virtual environment startup
$ python -m venv myvenv
$ cd myvenv/
$ source bin/activate
(myvenv)$ pip list
pip (7.1.2)
setuptools (18.2)
pip
Installation
(myvenv)$ pip install pysimplegui
(myvenv)$ pip list
Package Version
----------- -------
pip 20.2.2
PySimpleGUI 4.29.0
setuptools 18.2
sample.py
import PySimpleGUI as sg
sg.theme('DarkAmber') #Theme color
#Layout in the window
layout = [ [sg.Text('Some text on Row 1')],
[sg.Text('Enter something on Row 2'), sg.InputText()],
[sg.Button('Ok'), sg.Button('Cancel')] ]
#Create a window
window = sg.Window('Window Title', layout)
# "events"Of event loops and inputs to handle"Process to get values
while True:
event, values = window.read()
if event == sg.WIN_CLOSED or event == 'Cancel': # if user closes window or clicks cancel
break
print('You entered ', values[0])
window.close()
Run
(myvenv)$ python sample.py
Type "Hello, World!" And press "Ok" ...
The characters entered in the terminal are output.
Terminal output
You entered Hello, World!
Unlike web applications that use a browser, I felt that it was good because I could code with an awareness of "event loops".
Recommended Posts