-2

this is a part of my code, i'm trying to get the value from the Entry bf, but when i run it shows that: "AttributeError: 'NoneType' object has no attribute 'get'". Does anyone knows why that is happening?

Code:

from tkinter import *

window = Tk()
window.geometry("650x450+500+300")

def Calcular():
    print("teste")
    print(bf.get())

Geom = LabelFrame(window, text = "Dados Geométricos", font="Arial 12", width=200)
Geom.place(x=290, y=10)

Label(Geom, text ="bf: ", font="Arial 12").grid(column=0, row=0, sticky=E)

Label(Geom, text =" cm", font="Arial 12").grid(column=2, row=0, sticky=W)

bf = Entry(Geom, width=5, justify= RIGHT, font="Arial 12").grid(column=1, row=0)

btnCalcular = Button(window, text="Calcular", font="Arial 12", command=Calcular)
btnCalcular.place(x=50, y=180, width = 150)

window.mainloop()

2 Answers2

1

Split following line in 2:

bf = Entry(Geom, width=5, justify= RIGHT, font="Arial 12").grid(column=1, row=0)

like this

bf = Entry(Geom, width=5, justify= RIGHT, font="Arial 12")
bf.grid(column=1, row=0)

At the moment bf is not the Entry widget, but None returned from grid() Also note that normally you would use variable, e.g. IntVar, that is bind to entry widget

buran
  • 13,682
  • 10
  • 36
  • 61
1
bf = Entry(Geom, width=5, justify= RIGHT, font="Arial 12")
bf.grid(column=1, row=0)

The Cause of NoneType was due to the return type of grid(column=1, row=0) in your code.