【发布时间】:2013-12-05 19:11:55
【问题描述】:
摄氏到华氏——编写一个 GUI 程序,将摄氏温度转换为华氏温度。用户应该能够输入摄氏温度,单击按钮,然后看到等效的华氏温度。使用以下公式进行转换: F = 9/5C +32 F 是华氏温度,C 是摄氏温度。
这是我到目前为止的代码,我得到的错误是“invalid literal for int() with base 10: ''”我需要帮助才能让它正确运行。
#import
#main function
from tkinter import *
def main():
root=Tk()
root.title("Some GUI")
root.geometry("400x700")
#someothersting=""
someotherstring=""
#enter Celcius
L1=Label(root,text="Enter a Celcius temperature.")
E1=Entry(root,textvariable=someotherstring)
somebutton=Button(root, text="Total", command=convert(someotherstring))
somebutton.pack()
E1.pack()
L1.pack()
root.mainloop()#main loop
#convert Celcius to Fahrenheit
def convert(somestring):
thestring=""
thestring=somestring
cel=0
far=0
cel=int(thestring)
far=(9/5*(cel))+32
print(far)
【问题讨论】:
-
您在
someotherstring的字段中输入了什么,听起来您输入了“10C”或int()无法解析的内容。
标签: python user-interface tkinter python-3.3