【发布时间】:2017-04-25 17:57:12
【问题描述】:
这是一个带有 GUI 的温度转换器。我在 GUI 方面遇到问题。在我添加到 GUI 中之前,我的代码运行正确,现在说它已全部检出,但当我实际运行程序时什么都不会发生。我不知道是不是因为我可能需要 Tkinter 文件在同一个文件夹中?我之前从文件中获取文本或者我的 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)
【问题讨论】:
-
它也在 python 2 中
-
许多语言会自动为您调用
main,但Python 不是其中之一。尝试在末尾添加main()。