# -*- coding: UTF-8 -*-
from tkinter import *
from tkinter import ttk
def calculate(*args):
try:
value = float(Cels.get())
Fahr.set( value * (9/5) +32)
except ValueError:
pass
root = Tk()
root.title("****** 攝氏溫度 轉 華式溫度 *******")
mainframe = ttk.Frame(root, padding="3 3 12 12")
mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
mainframe.columnconfigure(0, weight=1)
mainframe.rowconfigure(0, weight=1)
Cels = StringVar()
Fahr = StringVar()
feet_entry = ttk.Entry(mainframe, width=7, textvariable=Cels)
feet_entry.grid(column=2, row=1, sticky=(W, E))
ttk.Label(mainframe, textvariable=Fahr).grid(column=2, row=2, sticky=(W, E))
ttk.Button(mainframe, text="Calculate", command=calculate).grid(column=1, row=3, sticky=E)
ttk.Button(mainframe, text="Quit", command= quit).grid(column=2, row=3, sticky=E)
ttk.Label(mainframe, text="請輸入 攝氏溫度 == ").grid(column=1, row=1, sticky=E)
ttk.Label(mainframe, text=" 相當於 ").grid(column=1, row=2, sticky=E)
ttk.Label(mainframe, text="華式溫度").grid(column=3, row=2, sticky=W)
for child in mainframe.winfo_children(): child.grid_configure(padx=5, pady=5)
feet_entry.focus()
root.bind('<Return>', calculate)
root.mainloop()