PySimpleGUI is a Python package that enables Python programmers of all levels to create GUIs. You specify your GUI window using a “layout” that contains widgets (they’re called “Elements” in PySimpleGUI). In this article, we will learn, how to make a calculator using PySimpleGUI in Python.
Before starting we need to install this package:
pip install PySimpleGUI
- Import the PySimpleGUI Module
- Create GUI layout and Window
- Add any number of widgets to the main window
- Apply the event Trigger on the widgets.
Below is what the GUI looks like:
Let’s create a GUI-based simple calculator using the Python PySimpleGUI module, which can perform basic arithmetic operation’s addition, subtraction, multiplication, and division.
Let’s Understand step by step implementation:-
Step1: Create Text Box, Buttons
For creating a text box, we will use Txt() method.
Syntax: Txt(Enter Text, *attr)
Here will use the read button using ReadFormButton() method.
Syntax: ReadFormButton(Enter Button Text, *attr)
Step 2: Create an infinite loop, read the button value and perform the operation.
Below is the full implementation :
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course