savings is referring to a global function not defined, you have a method called savings...thus you need
your also going to need an IntVar at least 1 for the savings value...and probably for each Entry as well. You want a button to calculate at the users request, otherwise it calculates the defaults. So calling savings should be done by a button and not the label.
self.savings
your also going to need an IntVar at least 1 for the savings value...and probably for each Entry as well. You want a button to calculate at the users request, otherwise it calculates the defaults. So calling savings should be done by a button and not the label.
from tkinter import * class Application(Frame): def __init__(self, master): Frame.__init__(self,master) self.grid() self.create_widgets() def create_widgets(self): self.label_1 = Label(self, text="Insert Income") self.label_2 = Label(self, text="Insert Cost") self.savings_var = IntVar() self.label_3 = Label(self, textvariable=self.savings_var) self.entry_1 = Entry(self) self.entry_2 = Entry(self) self.btn = Button(self, text='OK', command=self.savings) self.label_1.grid(row=0, sticky=E) self.label_2.grid(row=1, sticky=E) self.label_3.grid(row=2, sticky=E) self.entry_1.grid(row=0, column=1) self.entry_2.grid(row=1, column=1) self.btn.grid(row=3, column=1) def savings(self): value = float(self.entry_1.get()) - float(self.entry_2.get()) self.savings_var.set(value) root = Tk() root.title("Cost calculator") root.geometry("500x200") app = Application(root) root.mainloop()
Recommended Tutorials: