# -*- coding: utf-8 -*- import tkinter as tk class App: def __init__(self, root): self.root = root self.lbFahrenheit = tk.Label(root, text = '請輸入華氏溫度\n(Fahrenheit)', font="標楷體") self.eFahrenheit = tk.Entry(root, bg = 'lightgreen', bd = 2, font = "Aharoni", width = 30) self.btConversion = tk.Button(root, text = 'Conversion') self.lbCentigrade = tk.Label(root, font="Times 18 bold") self.lbFahrenheit.pack() self.eFahrenheit.pack() self.btConversion.pack() self.lbCentigrade.pack() self.eFahrenheit.bind('',self.FtoC) self.btConversion.bind('<1>', self.FtoC) def FtoC(self,event): f = float(self.eFahrenheit.get()) c = (f-32)*5/9 self.lbCentigrade.config(text = "攝氏{}C".format(c), relief = 'raised', height = 2, bg = 'pink', fg = 'blue',font = 'FrankRuehl 12 bold') def main(): root = tk.Tk() root.title("tk14.py") root.geometry("200x200") App(root) root.mainloop() if __name__=='__main__': main()