【发布时间】:2018-12-16 00:16:24
【问题描述】:
编写一个将摄氏温度转换为华氏温度的 GUI 程序。用户应该能够输入摄氏温度,单击按钮,然后看到等效的华氏温度。使用以下公式进行转换:
F= (9/5)C+32
F 是华氏温度,C 是摄氏温度。
这是我所拥有的,但是当我运行它时没有任何反应:
#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=lambda: convert(E1.get()))
somebutton.pack()
E1.pack()
L1.pack()
root.mainloop()#main loop
#convert Celcius to Fahrenheit
def convert(somestring):
if somestring != "":
cel=int(somestring)
far=(9/5*(cel))+32
print(far)
【问题讨论】:
-
你不能指望别人完全给你写代码,在这里询问问题/错误
-
你永远不会调用
main函数。