Learning how to code the compound interest rate in python as well as creating an investment calculator by using GUI.
Step 1: Getting Started
Open the Python module and click on the new file option.
Step 2: Setting Up
Type import tkinter to get GUI parts running.
Step 3: Class and Init Function Argument
Make sure to create a class and underneath it type in function def init. Inside the init function argument use self so that you can have access to attributes and methods of the class.
Step 4: Windows and Frames
After getting your init function setup make sure to creates main window and frames to get the GUI window initialized.
Step 5: Having Variables Investment
Have self. a variable name to set up the buttons for which should be which. Using proper variable names is recommended so that you don't confuse yourself and others when explaining your code. The variables are investmentAmt, year, and annualInterestRate which are used to find the futurevalue.
Caution: When naming variables don't use variables names that are predefined or that make no sense. This can either make your code not work or can confuse you which variables are which.
Ex: v = my steps
str = my steps
Step 6: Adding Frames to Window
Make sure to confirm by adding your frames to your windows so that you don't get a blank screen. This still does not mean you will get the window to work. You still need to add another function.
Step 7: Calculate Function With Button Click
The new function name can be something like calculate, anything related to investment, then add the investment equation. You should also take note of the code in the first picture since it has invAmt, years, and annual which use.entry.get() to access it from the GUI portion.
Step 8: Displaying Window
Add this code so that the window can get displayed on the screen.
Step 9: Adding a Click Button
Add clickable button to GUI to display the future value and make sure to put in your function that was used to store the compound interest formula inside the button code so that the button knows that's the function it should use to display the results.
Step 10: Using Estimated Values
Normally in the real world, our future value would be presented in exact values. But the numbers just get so long and tedious to keep track so just for this program, we are going to use import math to have access to the methods that round the future value.
Step 11: Use Math.floor()
To have an estimated value you should use math.floor(futurevalue). This does floor rounding meaning it will round the number DOWNWARDS to the nearest integer.
Ex if the result is 278.956 the estimated value will be 278
Step 12: Calling on Class
Make sure to have some a code like variable = myclass() at the very bottom all the way towards the left which is outside the function so that way it would have access to your whole code in your program.
Step 13: Final
If you followed the steps correctly your output screen should look like this. If it does then congratulations you have successfully created a working investment calculator in python as well as applying that in GUI. If you have any questions about certain steps let me know.