我不断得到一个无类型属性错误和idk如何修复它,因为我看了很多视频,没有帮助。 我不知道我做错了什么。 如有帮助,不胜感激!
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()
你在犯一个很常见的错误。 小部件的值将是nonetype
,因为您正在同一行上使用.pack
。
因此,您的代码:
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()
这应该是你想要的结果。 希望这有用!