python 在尝试获取 tkinter 条目值时出错
python is giving an error when trying to get tkinter entry value
我正在尝试在 python 中打印 tkinter 条目值
像这样。
from tkinter import *
root=Tk()
root.geometry("500x500")
def temperature():
print(celciusEntry.get())
farenheidLabel = Label(root, text = "farenheid").place(x=110, y=10)
farenheidAnswer = Label(root, text="=",).place(x=110, y=30)
celciusLabel = Label(root, text="celcuis").place(x=20, y=10)
celciusEntry = Entry(root, width=10,).place(x=20, y=30)
temperaturebtn=Button(root, height=1, text="convert temperature", command=lambda:temperature())
temperaturebtn.place(x=20,y=100)
mainloop()
但是我收到一条错误消息 object has no attribute 'get'
为什么我会收到此错误消息。
变化:
...
celciusEntry = Entry(root, width=10).place(x=20, y=30)
...
至
...
celciusEntry = Entry(root, width=10)
celciusEntry.place(x=20, y=30)
...
我正在尝试在 python 中打印 tkinter 条目值 像这样。
from tkinter import *
root=Tk()
root.geometry("500x500")
def temperature():
print(celciusEntry.get())
farenheidLabel = Label(root, text = "farenheid").place(x=110, y=10)
farenheidAnswer = Label(root, text="=",).place(x=110, y=30)
celciusLabel = Label(root, text="celcuis").place(x=20, y=10)
celciusEntry = Entry(root, width=10,).place(x=20, y=30)
temperaturebtn=Button(root, height=1, text="convert temperature", command=lambda:temperature())
temperaturebtn.place(x=20,y=100)
mainloop()
但是我收到一条错误消息 object has no attribute 'get'
为什么我会收到此错误消息。
变化:
...
celciusEntry = Entry(root, width=10).place(x=20, y=30)
...
至
...
celciusEntry = Entry(root, width=10)
celciusEntry.place(x=20, y=30)
...