Python - How to get entry widget to add instead of concatenate?

Viewed 455

I want to get two separate entry widgets to add whatever is in them, but problem right now is it is concatenating the numbers in the entry widget.

from tkinter import *

master = Tk()

class MainWindow:
    def __init__(self, master):
        self.master = master
        master.geometry("640x480")


def Calculate():
    entry1 = firstEntry.get()
    entry2 = secondEntry.get()
    result = entry1 + entry2
    print(result)


firstLabel = Label(text="First Value")
firstLabel.grid(row=1, column=1)

firstEntry = Entry(master)
firstEntry.grid(row=1, column=2)

addLabel = Label(text="+")
addLabel.grid(row=1, column=3)

secondEntry = Entry(master)
secondEntry.grid(row=1, column=4)

secondLabel = Label(text="Second Value")
secondLabel.grid(row=1, column=5)

equalsButton = Button(text="=", width=10, command=Calculate)
equalsButton.grid(row=2, column=3)

master.mainloop()
2 Answers
Related