0

I keep getting a none Type attribute error and idk how to fix it as i looked on many videos and none helped. i don't know what I'm doing wrong. any help is appreciated!

from tkinter import *

def find():
    user = whiteBox.get()
    print(user)
root = Tk()
weatherResult = StringVar()
weatherResult.set("Enter a Place")

weather = Label(root, textvariable=weatherResult).pack()
whiteBox = Entry(root).pack()
check = Button(root, text="find", command=find).pack()
root.mainloop()

1 Answers1

1

You are making a very common mistake. The value of your widget will be a NoneType, because you are using .pack on the same line.

So, your code:

from tkinter import *

def find():
    user = whiteBox.get()
    print(user)
root = Tk()
weatherResult = StringVar()
weatherResult.set("Enter a Place")

weather = Label(root, textvariable=weatherResult).pack()
whiteBox = Entry(root)
whiteBox.pack()
check = Button(root, text="find", command=find).pack()
root.mainloop()

This should be the result you want. Hope this helps!

10 Rep
  • 2,217
  • 7
  • 19
  • 33