Compound Interest GUI Calculator using PyQt5 in Python
One of the most significant factors that increased the usability of computer and digital technologies for common, less tech-savvy users is likely the development and widespread adoption of GUIs. GUIs are intuitive enough that even relatively unskilled employees without programming experience can use them. Because they are always designed with the user in mind rather than being primarily machine-centered, they have become the standard in software application programming.
The user is provided with information using manipulable visual widgets that don't require command-line input. These interface components respond to the user's interactions per the pre-programmed script, assisting each user's action. Since many GUIs represent text and graphical elements in standard formats, it is possible for programs using the same GUI software to share data. As it is patched and developed, the same software application or os version may present distinct or marginally distinct GUIs. The appearance of an application may change depending on user needs or to enhance the user experience, even if the application's core functionality and functions remain unchanged, as was the case with the various Windows versions over time.
A graphical interface (GUI) is a user interface that lets users interact with electronic devices like computers and smartphones by using menus, icons, and other visual cues (graphics). In contrast to text-based interfaces, which only display data and commands as text, GUIs visualize information and related user controls.
Commands were entered at the DOS prompt to ask for responses from a desktop. These commands' usage and the requirement for precise spelling led to an unwieldy and ineffective user interface.
Advantages of GUI:
Quick and easy access to any screen area allows for full-screen interaction. You merely click a button or an icon to invoke the necessary function. The general public now has access to a wide range of systems for daily use, regardless of experience or knowledge, thanks to the simplicity of GUIs. Additionally, Tkinter provides access to the widgets' geometric configuration, which can arrange the widgets in the parent windows.
Disadvantages of GUI:
Due to the numerous menus, some tasks may take a while. The Help file must be used to search for hidden commands. Applications with a GUI require more RAM to operate. Compared to different interface types, it consumes more processing power.
PyQt5 is one of several solutions that Python offers for creating GUI applications. Cross-platform GUI toolkit PyQt5 is a collection of Python interfaces for Qt version 5. With the capabilities and convenience of use that this library offers, one can create an interactive computer program very quickly. Front-end and Back-end make up a GUI application. In order to speed up development & allow more time to be spent on back-end tasks, PyQt5 has developed a tool called "QtDesigner" that allows one to drag and drop elements to create the front-end. Riverbank Computing is the company in charge of developing and maintaining PyQt. A most recent stable version is PyQt6. The PyQt main version's release cycle matches Qt's, as per the release history. The PyQt codebase is a complex system with both C++ and Py code at its core. It is therefore more difficult to create and download it from the sources than other Python libraries. Even more detailed installation instructions may be found in the instructions for the specific PyQt version we want to utilise. It comes with installation instructions for both the GPL and the paid versions. Before the window shows on the screen, a few essential concepts regarding the organisation of applications in the Qt world must be explained. Unless you're already familiar with event loops, you can proceed to the next part without risk. The cornerstone of all Qt programs is the QApplication class. For each application to function, there must be a single QApplication object. The primary loop in your programme that manages all interface with the GUI is housed in this object.
pip install pyqt5 pip install pyqt5-tools
utilising a QT designer tool to create a signup form. To developed this skill, buttons, text boxes, etc., no coding is necessary! It is a drag-and-drop kind of setting. Therefore, using PyQt is easier than Tkinter.
Introduction to Compound Interest GUI calculator:
The interest that is given on both the capital and the interest that is compounded at regular intervals is known as compound interest. The accrued Interest is combined with the existing principal amount at regular intervals, and the Interest is then projected for the school president. The initial principal plus the interest that has already accrued make up the new principal.
Compound Interest = Interest on Principal + Compounded Interest at Standard Intervals
Compound interest can be calculated in two stages. The starting amount of the main loan will be multiplied by one, along with the annualized rate rising to the amount of compounds periods minus one, to determine the final amount. The complete amount of the loan's initial principal will be deducted from the resultant value in the following step. We will receive compound interest from this, or CI.
By multiplying the real amount of the loan, asset, or principal by the annual interest rate, we may determine the annual compound interest. The compound interest for the second year will then be calculated by adding that sum to the principal and multiplying it by the rate of interest once more.
from tkinter import * def reset(): principalField.delete(0, END) rateField.delete(0, END) numberField.delete(0, END) timeField.delete(0, END) resultField.delete(0, END) principalField.focus_set() def compound_interest(): principal = float(principalField.get()) rate_of_interest = float(rateField.get()) number = float(numberField.get()) time = float(timeField.get()) amount = principal * pow((1 + (rate_of_interest / (100 * number))), number * time) ci = amount - principal resultField.insert(10, ci) if __name__ == "__main__": guiWindow = Tk() guiWindow.title("Compound Interest Calculator") guiWindow.geometry("500x500+500+250") guiWindow.resizable(0, 0) guiWindow.configure(bg = "#ffffff") guiLabel = Label(guiWindow,text = "CALCULATE THE \nCOMPOUND INTEREST", font = ("Arial", 20),fg = "#211600",bg = "#f0c33c") guiLabel.place(x = 60,y = 10) labelOne = Label(guiWindow,text = "Principal Amount (Rs.):",bg = "#f0c33c",fg = "#4a3200" ) labelTwo = Label(guiWindow,text = "Rate of Interest (%):",bg = "#f0c33c",fg = "#4a3200") labelThree = Label(guiWindow,text = "Number of Times (n):",bg = "#f0c33c", fg = "#4a3200" ) labelFour = Label(guiWindow,text = "Time Period (Years):",bg = "#f0c33c",fg = "#4a3200") labelFive = Label(guiWindow,text = "Compound Interest (C.I.):",bg = "#f0c33c",fg = "#4a3200") labelOne.place(x = 72, y = 120) labelTwo.place(x = 72, y = 160) labelThree.place(x = 72, y = 200) labelFour.place(x = 72, y = 240) labelFive.place(x = 72, y = 340) principalField = Entry(guiWindow,bg = "#fcf9e8",fg = "#211600") rateField = Entry(guiWindow, bg = "#fcf9e8",fg = "#211600") numberField = Entry(guiWindow, bg = "#fcf9e8", fg = "#211600") timeField = Entry( guiWindow, bg = "#fcf9e8",fg = "#211600") resultField = Entry(guiWindow,bg = "#fcf9e8",fg = "#211600" ) principalField.place(x = 250, y = 120) rateField.place(x = 250, y = 160) numberField.place(x = 250, y = 200) timeField.place(x = 250, y = 240) resultField.place(x = 250, y = 340) resultButton = Button(guiWindow, text = "CALCULATE", bg = "#135e96", fg= "#fcf9e8", command = compound_interest) resetButton = Button(guiWindow, text = "RESET", bg = "#d63638", fg = "#fcf0f1", command = reset ) resultButton.place(x = 280, y = 280) resetButton.place(x = 300, y = 380) guiWindow.mainloop()
Import all required libraries next define the reset Function and also delete the entries in all entry fields. Set the focus to the entry field. Next define the function to calculate the compound interest further get the values from the entry fields also calculate the compound interest. Print the resultant value in result field. Next coming to the main function create a instance of the tk() class and define the title of GUI window ,define the geometry for the window also disabling the resizable option and set the background colour for the window. Heading on the window. Placing the label on the window next creating a principal amount label also create a rate of interest, number of times, time, compound Interest. Use place() method to place the above labels on the window. Next create a result button and reset button next run the window.