from tkinter import *
my_window = Tk()
def converter():
F = float(entry_input.get())
T = (F-32)*5/9
display_Temp["text"] = str(T)
Label(my_window,text="Enter Temperature in Farenheit = ").grid(row=0,column=0)
display_Temp = Label(my_window).grid(row=1,column=1)
entry_input = Entry(my_window).grid(row=0,column=1)
button = Button(my_window,text="Convert to Deg Celcius",command = converter,bd=8,relief="raised").grid(row=1,column=0)
my_window.mainloop()
我在GUI窗口中输入了20 F,该窗口的创建是将华氏值转换为摄氏度。但是,当我按下转换器按钮时,它给出以下错误消息:AttributeError:'NoneType'对象没有属性'get'
请参考图片以了解错误
答案 0 :(得分:0)
几何管理器(grid
,pack
,place
)返回None;您不应与grid
小部件分配同一行。
import tkinter as tk # <-- avoid star imports
def converter():
F = float(entry_input.get())
T = (F - 32) * 5 / 9
display_Temp["text"] = str(T)
my_window = tk.Tk()
tk.Label(my_window, text="Enter Temperature in Farenheit = ").grid(row=0, column=0)
display_Temp = tk.Label(my_window)
display_Temp.grid(row=1, column=1)
entry_input = tk.Entry(my_window)
entry_input.grid(row=0, column=1)
button = tk.Button(my_window, text="Convert to Deg Celcius", command=converter, bd=8, relief="raised")
button.grid(row=1, column=0)
my_window.mainloop()