# Fahrenheit to Celcius
def f2c():
userInput = tempEntry.get().lower()
thisEquation = "Fahrenheit to Celcius"
if userInput == "":
textWid.insert(END,"-- " + thisEquation + " --")
textWid.insert(END,"\n")
textWid.insert(END,temp_equations[thisEquation])
textWid.insert(END,"\n")
textWid.insert(END,"\n")
elif userInput.isdigit():
textWid.insert(END,"Fahrenheit = ")
textWid.insert(END,str(((float(userInput) - 32) * (5/9))))
textWid.insert(END,"\n")
else:
textWid.insert(END,"Invalid entry for"+" "+thisEquation)
textWid.insert(END,"\n")
# Fahrenheit to Kelvin
def f2k():
userInput = tempEntry.get().lower()
thisEquation = "Fahrenheit to Kelvin"
if userInput == "":
textWid.insert(END,"-- " + thisEquation + " --")
textWid.insert(END,"\n")
textWid.insert(END,temp_equations[thisEquation])
textWid.insert(END,"\n")
textWid.insert(END,"\n")
elif userInput.isdigit():
textWid.insert(END,"Fahrenheit = ")
textWid.insert(END,str(((5/9)*(float(userInput) - 32) + 273.15)))
textWid.insert(END,"\n")
else:
textWid.insert(END,"Invalid entry for"+" "+thisEquation)
textWid.insert(END,"\n")
userInput 是一个全局定义的 Tkinter 输入框。我强烈怀疑我的问题源于这两个方程,但我已经尝试过多次重新处理它们。
我的华氏度到摄氏度的转换器总是返回 0.0 华氏度到开尔文的转换器每次大约 20 折。
完全难倒这里的家伙,任何帮助将不胜感激。