Zinsrechner (Zeit) GUI Python
Verfasst: Montag 28. Juni 2021, 22:31
Hallo Zusammen!
Ich versuche einen Zinsrechner zu erstellen (GUI), der die Zeit berechnet, die es benötigt um auf einen gewissen Wunschbetrag zu kommen.
Das ist der Quellcode, den ich gefunden und versucht habe zu ändern.
# import all classes / functions from the tkinter
from tkinter import *
# Function for clearing the
# contents of all entry boxes
def clear_all() :
# whole content of entry boxes is deleted
anfangskapital_field.delete(0, END)
zinssatz_field.delete(0, END)
zeit_field.delete(0, END)
wunschbetrag_field.delete(0, END)
# set focus on the principle_field entry box
anfangskapital_field.focus_set()
# Function to find compound interest
def calculate_wunschbetrag():
# get a content from entry box
anfangskapital = int(anfangskapital_field.get())
zinssatz = float(zinssatz_field.get())
zeit = int(zeit_field.get())
# Calculates compound interest
wunschbetrag = anfangskapital * (pow((1 + zinssatz/ 100), zeit))
# insert method inserting the
# value in the text entry box.
wunschbetrag_field.insert(10, wunschbetrag)
# Driver code
if __name__ == "__main__" :
# Create a GUI window
root = Tk()
# Set the background colour of GUI window
root.configure(background = 'light green')
# Set the configuration of GUI window
root.geometry("400x250")
# set the name of tkinter GUI window
root.title("Zinsrechner")
# Create a Principle Amount : label
label1 = Label(root, text = "Anfangskapital : ",
fg = 'black', bg = 'red')
# Create a Rate : label
label2 = Label(root, text = "Zinssatz(%) : ",
fg = 'black', bg = 'red')
# Create a Time : label
label3 = Label(root, text = "Zeit : ",
fg = 'black', bg = 'red')
# Create a Compound Interest : label
label4 = Label(root, text = "Wunschbetrag : ",
fg = 'black', bg = 'red')
# grid method is used for placing
# the widgets at respective positions
# in table like structure .
# padx keyword argument used to set padding along x-axis .
# pady keyword argument used to set padding along y-axis .
label1.grid(row = 1, column = 0, padx = 10, pady = 10)
label2.grid(row = 2, column = 0, padx = 10, pady = 10)
label3.grid(row = 3, column = 0, padx = 10, pady = 10)
label4.grid(row = 5, column = 0, padx = 10, pady = 10)
# Create a entry box
# for filling or typing the information.
anfangskapital_field= Entry(root)
zinssatz_field= Entry(root)
zeit_field= Entry(root)
wunschbetrag_field= Entry(root)
# grid method is used for placing
# the widgets at respective positions
# in table like structure .
# padx keyword argument used to set padding along x-axis .
# pady keyword argument used to set padding along y-axis .
anfangskapital_field.grid(row = 1, column = 1, padx = 10, pady = 10)
zinssatz_field.grid(row = 2, column = 1, padx = 10, pady = 10)
zeit_field.grid(row = 3, column = 1, padx = 10, pady = 10)
wunschbetrag_field.grid(row = 5, column = 1, padx = 10, pady = 10)
# Create a Submit Button and attached
# to calculate_ci function
button1 = Button(root, text = "Submit", bg = "red",
fg = "black", command = calculate_wunschbetrag)
# Create a Clear Button and attached
# to clear_all function
button2 = Button(root, text = "Clear", bg = "red",
fg = "black", command = clear_all)
button1.grid(row = 4, column = 1, pady = 10)
button2.grid(row = 6, column = 1, pady = 10)
# Start the GUI
root.mainloop()
Wie stellle ich den Code nun so um , dass er mir die Zeit aussrechnet?
Ich versuche einen Zinsrechner zu erstellen (GUI), der die Zeit berechnet, die es benötigt um auf einen gewissen Wunschbetrag zu kommen.
Das ist der Quellcode, den ich gefunden und versucht habe zu ändern.
# import all classes / functions from the tkinter
from tkinter import *
# Function for clearing the
# contents of all entry boxes
def clear_all() :
# whole content of entry boxes is deleted
anfangskapital_field.delete(0, END)
zinssatz_field.delete(0, END)
zeit_field.delete(0, END)
wunschbetrag_field.delete(0, END)
# set focus on the principle_field entry box
anfangskapital_field.focus_set()
# Function to find compound interest
def calculate_wunschbetrag():
# get a content from entry box
anfangskapital = int(anfangskapital_field.get())
zinssatz = float(zinssatz_field.get())
zeit = int(zeit_field.get())
# Calculates compound interest
wunschbetrag = anfangskapital * (pow((1 + zinssatz/ 100), zeit))
# insert method inserting the
# value in the text entry box.
wunschbetrag_field.insert(10, wunschbetrag)
# Driver code
if __name__ == "__main__" :
# Create a GUI window
root = Tk()
# Set the background colour of GUI window
root.configure(background = 'light green')
# Set the configuration of GUI window
root.geometry("400x250")
# set the name of tkinter GUI window
root.title("Zinsrechner")
# Create a Principle Amount : label
label1 = Label(root, text = "Anfangskapital : ",
fg = 'black', bg = 'red')
# Create a Rate : label
label2 = Label(root, text = "Zinssatz(%) : ",
fg = 'black', bg = 'red')
# Create a Time : label
label3 = Label(root, text = "Zeit : ",
fg = 'black', bg = 'red')
# Create a Compound Interest : label
label4 = Label(root, text = "Wunschbetrag : ",
fg = 'black', bg = 'red')
# grid method is used for placing
# the widgets at respective positions
# in table like structure .
# padx keyword argument used to set padding along x-axis .
# pady keyword argument used to set padding along y-axis .
label1.grid(row = 1, column = 0, padx = 10, pady = 10)
label2.grid(row = 2, column = 0, padx = 10, pady = 10)
label3.grid(row = 3, column = 0, padx = 10, pady = 10)
label4.grid(row = 5, column = 0, padx = 10, pady = 10)
# Create a entry box
# for filling or typing the information.
anfangskapital_field= Entry(root)
zinssatz_field= Entry(root)
zeit_field= Entry(root)
wunschbetrag_field= Entry(root)
# grid method is used for placing
# the widgets at respective positions
# in table like structure .
# padx keyword argument used to set padding along x-axis .
# pady keyword argument used to set padding along y-axis .
anfangskapital_field.grid(row = 1, column = 1, padx = 10, pady = 10)
zinssatz_field.grid(row = 2, column = 1, padx = 10, pady = 10)
zeit_field.grid(row = 3, column = 1, padx = 10, pady = 10)
wunschbetrag_field.grid(row = 5, column = 1, padx = 10, pady = 10)
# Create a Submit Button and attached
# to calculate_ci function
button1 = Button(root, text = "Submit", bg = "red",
fg = "black", command = calculate_wunschbetrag)
# Create a Clear Button and attached
# to clear_all function
button2 = Button(root, text = "Clear", bg = "red",
fg = "black", command = clear_all)
button1.grid(row = 4, column = 1, pady = 10)
button2.grid(row = 6, column = 1, pady = 10)
# Start the GUI
root.mainloop()
Wie stellle ich den Code nun so um , dass er mir die Zeit aussrechnet?