So I've been trying to make a VERY simple calculator program, but I tried so many things, and all of my methods failed. I've been at this for weeks, and I'm pretty frustrated up to this point. Nothing calls back on the entry box correctly, and although at certain points I was able to make numbers appear on the entry widget, I couldn't interact with them (e.g. add, subtract, etc.)
For now, I'm trying to make my program add 1+1 so it'll equal 2. However, Python IDLE is telling me that I have indentation problems. As far as I know, everything looks fine. I also copied bits of another calculator program elsewhere. If anyone knows a detailed source on entry boxes, please let me know. Thanks in advance!
from Tkinter import * root=Tk() class Calculator(Frame): def __init__(self, master=None): Frame.__init__(self, master) self.pack() display = StringVar() ent=Entry(self, textvariable=display).pack(side=TOP) self.onebutton=Button(self, text="1", command=self.number).pack() self.twobutton=Button(self, text="2", command=self.number).pack() self.eqlbutton=Button(self, text="=", command=self.equal).pack() def number(self, event): lambda w=display, s=' %s '%text:w.set(w.get() + s)) def equal(self, event): lambda e, s=self, w=display: s.calc(w), '+') def calc(self, display): try: display.set(eval(display.get())) except: display.set("ERROR") Calculator().mainloop()