I tried to touch Python's GUI library "PySimple GUI"

undefined 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.

The site that I used as a reference

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.

Development environment

PySimpleGUI First installed by pip

pip install pysimplegui

This is OK

What to create

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.

Code created and results

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 result1.png

Result display result2.png

The calculation result is displayed properly

Summary

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

I tried to touch Python's GUI library "PySimple GUI"
I tried to touch jupyter
I tried to touch Python (installation)
I tried to touch Tesla's API
I tried to touch the COTOHA API
I tried to touch Python (basic syntax)
I tried to touch the API of ebay
I tried to extend Python's Active Record framework
I tried to debug.
I tried to paste
I tried to touch the CSV file with Python
I tried to learn PredNet
I tried to organize SVM.
I tried to implement PCANet
I tried the changefinder library!
I tried to reintroduce Linux
I tried to introduce Pylint
I tried to summarize SparseMatrix
I tried to implement StarGAN (1)
I tried to make GUI tic-tac-toe with Python and Tkinter
I tried using a library (common thread) that makes Python's threading package easier to use
I tried to implement Deep VQE
I tried to create Quip API
I tried to explain Pytorch dataset
I tried Watson Speech to Text
I tried to implement hierarchical clustering
I tried to organize about MCMC.
I tried to implement Realness GAN
I tried to move the ball
I tried to estimate the interval.
I tried to display GUI on Mac with X Window System
I tried to create a linebot (implementation)
I tried to summarize Python exception handling
I tried to implement PLSA in Python
I tried using Azure Speech to Text.
I tried to implement Autoencoder with TensorFlow
I tried to summarize the umask command
I tried to implement permutation in Python
I tried to create a linebot (preparation)
I tried to recognize the wake word
PyPi debut I tried to pip install a library to check Japanese holidays
I tried to get started with Hy
I tried to implement PLSA in Python 2
I tried to classify text using TensorFlow
I tried to summarize the graphical modeling.
I tried adding post-increment to CPython Implementation
I tried to implement ADALINE in Python
I tried to let optuna solve Sudoku
I tried to estimate the pi stochastically
I tried to implement PPO in Python
I tried to implement CVAE with PyTorch
I tried to make a Web API
I tried to visualize the model with the low-code machine learning library "PyCaret"
I tried to solve TSP with QAOA
[Python] I tried to calculate TF-IDF steadily
I tried shortening Python's FizzBuzz little by little
I tried my best to return to Lasso
I tried to summarize Ansible modules-Linux edition
I tried to predict Covid-19 using Darts
I tried to extract named entities with the natural language processing library GiNZA
[Python] Deep Learning: I tried to implement deep learning (DBN, SDA) without using a library.