This is VisualCalc, a basic calculator created entirely in Python. In this project, PySide6 was used, one of the most powerful and versatile libraries for creating graphical interfaces in Python. PySide6 is an official Qt binding for Python, allowing you to create feature-rich applications with a modern look and feel.
- Run the program.
- Enter two numbers when prompted.
- Enter an operator (+, -, *, / or (^ or P)) to perform the desired operation.
- The program will display the result of the operation.
- Validates user input to ensure only valid numbers and operators are used.
- Handles exceptions gracefully, preventing the program from crashing.
- Provides a simple and intuitive interface for performing calculations.
- Buttons: Calculator buttons are created using PySide6's QPushButton class. Each button represents a specific number, operator, or function (such as clearing or calculating the result). The cls_button custom class is an extension to QPushButton that allows you to further configure the style and behavior of buttons. Below is an example of how we configure a button.
- Layout: To organize the buttons in a grid, we use QGridLayout. The cls_buttonsgrid class extends QGridLayout and is responsible for adding and positioning each button in the grid, as well as connecting button signals to the appropriate slots that perform calculator functions.
- Display: The calculator display is an instance of cls_display, a custom class that manages the display of numbers and results of operations. It is connected to several signals that react to user input and update the interface as needed.
- Slots and Connections: We use the PySide6 concept of slots to define the functions that will be executed in response to the events generated by the buttons. For example, the _mtd_invertnumber method inverts the sign of the number currently displayed on the display: