-2

I am a beginner in python. Refer the below code.

def FindSqr():
    cal = int(ent.get())
    ans = str(cal*cal)
    lbl2 = Label(root,text=ans).pack()
root = Tk()
lbl1 = Label(root,text="Enter Number Below:").pack()
ent = Entry(root).pack()
btn = Button(root,text="Calculate",command=FindSqr).pack()
root.mainloop()

Error is:

    cal = int(ent.get())
AttributeError: 'NoneType' object has no attribute 'get'
vvvvv
  • 25,404
  • 19
  • 49
  • 81
Vtechster
  • 47
  • 3

1 Answers1

0

You can't initialize and layout a widget on the same line if you want to use it later. Use 2 lines to make your widgets.

ent = Entry(root)
ent.pack()
Novel
  • 13,406
  • 2
  • 25
  • 41