I need help with making my calculator
MRAB
python at mrabarnett.plus.com
Fri May 19 22:06:15 EDT 2017
On 2017-05-20 02:42, garsink at gmail.com wrote:
> m using Python 3.4.2
> This is my code:
>
>
> from tkinter import*
>
> def iCalc(source, side):
> storeObj= Frame(source, borderwidth= 1, bd= 4, bg="powder blue")
> storeObj.pack(side=side, expand=YES, fill=BOTH)
> return storeObj
>
> def button (source, side, text, command=None):
> storeObj= Button(source, text=text, command=command)
> storeObj.pack(side=side, expand=YES, fill=BOTH)
> return storeObj
>
> class app(Frame):
> def __init__(self):
> Frame.__init__(self)
> self.option_add('*Front', 'arial 20 bold')
> self.pack(expand=YES, fill=BOTH)
> self.master.title('Calculator')
>
> display= StringVar()
> Entry(self, relief=RIDGE,
> textvariable=display, justify='right', bd=30, bg="powder blue").pack(side=TOP, expand=YES,
> fill=BOTH)
> for clearBut in(["CE"], ["C"]):
> erase = iCalc(self, TOP)
> for ichar in clearBut:
> button(erase, LEFT, ichar,
> lambda storeObj=display, q=ichar: storeObj.set(''))
>
> for NumBut in ("789/", "456*", "123-", "0.+"):
> FunctionNum = iCalc(self, TOP)
> for iEquals in NumBut:
> button(FunctionNum, LEFT, iEquals,
> lambda storeObj=display, q=iEquals: storeObj.set(storeObj.get() + q))
>
> EqualsButton=iCalc(self, TOP)
> for iEquals in "=":
> if iEquals == '=':
> btniEquals= button(EqualsButton, LEFT, iEquals)
> btniEquals.bind('<ButtonRelease-1>',
> lambda e, s=self, storeObj=display: s.calc(storeObj), '+')
> else:
> btniEquals= buton(EqualsButton, LEFT, iEquals,
> lambda storeObj=display, s=' %s '%Equals: storeObj.set(storeObj.get()+s))
>
>
>
> def calc(self, display):
> try:
> display.set(eval(display.get()))
> except:
> display.set("Type an actual equation please!")
>
>
>
> if __name__ == '__main__':
> app().mainloop()
>
You haven't said what the problem is, but it's because the 'calc' method
isn't indented enough. You've indented the '__init__' method correctly,
but not the 'calc' method.
More information about the Python-list
mailing list