0
我在寫一個GUI,將攝氏溫度轉換爲華氏溫度,反之亦然。 我需要輸入框的攝氏溫度從0.0開始(這是)和華氏從32.0開始(我不知道該怎麼做)。如何獲得具有設定值的輸入框? 這是我對程序的構造函數的代碼:tkinter設置值在輸入框中
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)
謝謝你,這是很容易做到。 – tinydancer9454