我正在编写一个将摄氏度转换为华氏度的 GUI,反之亦然。我需要摄氏度的输入框从 0.0 开始(它确实如此),华氏度从 32.0 开始(我不知道该怎么做)。如何有一个设置值的输入框?这是我用于程序构造函数的代码:
class TempFrame(Frame):
"""FUI for the program to convert between Celsius and Fahrenheit"""
def __init__(self):
"""Sets up the window and widgets"""
self.celciusVar= 0.0
self.fahrenheitVar= 32.0
Frame.__init__(self)
self.master.title("Temperature Conversion")
self.grid()
celsiusLabel = Label(self, text= "Celsius")
celsiusLabel.grid(row = 0, column = 0)
self.celsiusVar= DoubleVar()
celsiusEntry = Entry(self, textvariable = self.celsiusVar)
celsiusEntry.grid(row = 1, column = 0)
fahrenheitLabel = Label(self, text= "Fahrenheit")
fahrenheitLabel.grid(row = 0, column = 1)
self.fahrenheitVar= DoubleVar()
fahrenheitEntry = Entry(self, textvariable= self.fahrenheitVar)
fahrenheitEntry.grid(row = 1, column = 1)
button_1 = Button(self, text= ">>>>", command= self.celToFahr)
button_1.grid(row = 2, column = 0)
button_2 = Button(self, text= "<<<<", command=self.fahrToCel)
button_2.grid(row = 2, column = 1)