I am a beginner in programming, but I want to make a GUI application with Python, and since I learned about "PySimpleGUI", I would like to summarize it.
● Which GUI library is recommended for Python? : What is a GUI? Has introduced four libraries for creating GUI applications in Python.
● If you use Tkinter, try using PySimpleGUI: This is an introductory article about "PySimple GUI" that allows you to create a GUI with a simpler description than "Tkinter" that is built in as standard in Python. This time, I will try to make a GUI using this "PySimple GUI".
● Official Document: This is the official document of "PySimple GUI" mentioned above.
PySimpleGUI First installed by pip
pip install pysimplegui
This is OK
Since this is my first time, I would like to create a system in which the sum of two values is displayed when the button is pressed.
Here is the code I wrote and the result. Most of the code on the following site is reprinted. If you use Tkinter, try using PySimpleGUI
calcGUI.py
#! -*- coding:utf-8 -*-
import PySimpleGUI as sg
sg.theme('DarkAmber') #The theme is dark because it's cool
#Text and button layout
layout = [[sg.Text('Find the sum of a and b')],
[sg.Text('a'),sg.InputText(key='num1')],
[sg.Text('b'),sg.InputText(key='num2')],
[sg.Button('Calculation execution')],]
#Show window
window = sg.Window('window1',layout)
#Event loop
while True:
event, values = window.read()
if event == 'Calculation execution':
result = float(values['num1'])+float(values['num2'])
show_message = "The answer is"+str(result)+"is."
print(show_message)
sg.popup(show_message)
#close the window
window.close()
For some reason, the program didn't work unless I wrote a print (message) to display the pop-up.
Calculation screen
Result display
The calculation result is displayed properly
The syntax of PySimpleGUI was intuitive and easy to understand, and it was easy to create a GUI. There seems to be a lot of things I can do, so I will study.
Recommended Posts