带GUI问题的温度转换器
问题描述:
这是一个带有GUI的温度转换器。我在GUI方面遇到问题。在我添加到GUI之前,我的代码正确运行,现在说它已全部检出,但实际运行该程序时不会发生任何事情。我不知道是否因为我需要Tkinter文件可能位于同一个文件夹中?我之前从文件中获取文本时遇到过这个问题,或者如果我的GUI只是完全编程错误!谢谢!带GUI问题的温度转换器
#import
#main function
from Tkinter import *
def main():
root=Tk()
root.title("Temperature Converter")
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=0 dont need these in python
# far=0
cel=int(somestring)
far=(9/5*(cel))+32
print(F)
答
add main()并将F更改为far。我还在示例中添加了标签,说明转换是什么!:)希望这有助于。
#import
#main function
from Tkinter import *
def main():
root=Tk()
root.title("Temperature Converter")
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, label):
if somestring != "":
cel=int(somestring)
far=(9/5*(cel))+32
answer = str(cel) + " Converted to Farenheit = " + str(far)
label.config(text=answer)
main()
它是在Python 2以及 –
很多语言会自动调用'main',但Python不是其中之一。尝试在末尾添加'main()'。 – Kevin