0

I wrote the code below for a program that calculates the 'delta' that we use for second degree equations. I already wrote a calculator, which gets the numeric value from the entry like this: firstnum=entry.get().

However, when I tried to do same on the delta, I get the error:

AttributeError: 'NoneType' object has no attribute 'get'

from tkinter import
from tkinter.font import Font
import sys*
    
# window interface
r = Tk()
r.geometry("300x500")
r.configure(bg="#414d61")
   
    
# commands
def clear():
    r.quit()
    
    
def delta():
    ax = entry_ax.get()
    bx = entry_bx.get()
    c = entry_c.get()
    result = bx * bx - 4 * ax * c
    entry_delta.insert(0, result)
    
    
# text interface
text = Text(r)
My_font = Font(family="Arial Rounded MT Bold", size=12)
    
# labels and frames
label_top = Label(r, bg="#414d61", text="x²    +  (", font=My_font).place(x=80, y=200)
label_top2 = Label(r, bg="#414d61", text="    x)    +", font=My_font).place(x=140, y=200)
label_top3 = Label(r, bg="#414d61", text="    =0", font=My_font).place(x=200, y=200)
entry_ax = Entry(r, bg="white", width=2).place(x=60, y=202)
entry_bx = Entry(r, bg="white", width=2).place(x=138, y=202)
entry_c = Entry(r, bg="white", width=2).place(x=198, y=202)
entry_delta = Entry(r, bg="white", width=20).place(x=85, y=350)
# Buttons
b1 = Button(r, bg="#414d61", text="Calculate Delta", font=My_font, command=delta, height=1, width=20)
b1.place(x=40, y=300)
b2 = Button(r, bg="#414d61", text="Exit", font=My_font, command=clear, height=1, width=20)
b2.place(x=40, y=400)
    
# entries
entry = Label(r, bg="#414d61", text="Delta Calculator (basic gui version)", font=My_font, width=30)
entry.place(x=5, y=100)
    
r.mainloop()
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
  • 1
    Look at [this](https://stackoverflow.com/a/66385069/11106801) – TheLizzard Mar 06 '21 at 21:04
  • The problem is that you have `variable = Entry(...).palace(...)`. The variable will always be `None` – TheLizzard Mar 06 '21 at 21:05
  • 1
    Does this answer your question? [Tkinter: AttributeError: NoneType object has no attribute ](https://stackoverflow.com/questions/1101750/tkinter-attributeerror-nonetype-object-has-no-attribute-attribute-name) – TheLizzard Mar 06 '21 at 21:13

1 Answers1

0

Ok this is a very common mistake. When you create your Entry you do this:

variable = Entry(...).place(...)

That creates the entry then immediately calls its .place method. It stores whatever .place returns (always None) to variable. What you want to do is this:

variable = tk.Entry(...)
variable.place(...)
TheLizzard
  • 7,248
  • 2
  • 11
  • 31