Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Nancy Melucci
Nancy Melucci
Courses Plus Student 34,558 Points

Extracting numeric values from tkinter entry boxes in Python

I am tasked with making a simple calculator to take a purchase amount and calculate total amount paid (with interest) and monthly payments. I don't have that much experience with the GUI library tkinter, so I am struggling with how to make the entry boxes yield the float and int variables necessary to complete the task. I have looked at so many error messages and so many online examples of how to do it that I just can't interpret. I know there isn't a lot of tkinter stuff here but I am hoping someone can show me how to turn the entries into amount, rate and years...the code below is for an intermediate stage. I'll deal with interest form once I have the correcly parsed numbers.


from tkinter import *
from tkinter import messagebox

def multiply(var1, var2, var3):
    product = var1 * var2 * var3
    return product

def btnClick(event):
    x = float(entry.get())

main = Tk()
main.title("Assignment 16")

main["bg"] = "#000066"

lblFirst = Label(main, text="Amount to Pay: ")
lblFirst.grid(row=0, column=3, pady=5)

amount = " "
entry = Entry(main, width=20)
entry.grid(row=0, column=4)

lblSecond = Label(main, text="Interest Rate (like 7.5): ")
lblSecond.grid(row=2, column=3, pady=10)

rate = " "
entry2 = Entry(textvariable=rate)
entry2.grid(row=2, column=4)

lblThird = Label(main, text="Years to Pay: ")
lblThird.grid(row=4, column=3, pady=15)

years = " "
entry3 = Entry(textvariable=years)
entry3.grid(row=4, column=4)

num3 = int(years)

lblFourth = Label(main, text="Monthly Payment: ")
lblFourth.grid(row=6, column=3, pady=15)
lblFourthTwo = Label(main, text="XXXXX")
lblFourthTwo.grid(row=6, column=4)
lblFifth = Label(main, text="Total of Paymenta: ")
lblFifth.grid(row=8, column=3, pady=15)
lblFifthTwo = Label(main, text="XXXXX")
lblFifthTwo.grid(row=8, column=4)

button1 = Button(main, text="Convert", width=10, command=btnClick)
button2 = Button(main, text="Calculate", width=10, command=multiply(amount, rate, years))
button1.grid(padx=20, pady=20)
messagebox(amount, rate, years)