from tkinter import *
root=Tk()
root.title("Fahrenheit")
root.geometry("180x180")
var_C=StringVar()
lb1=Label(root,text="摄氏温度C:")
lb1.grid()
var_F=StringVar()
lb2=Label(root,text="华氏温度F:")
lb2.grid(row=1,column=0)
e1=Entry(root,textvariable=var_C)
e1.grid(row=0,column=1)
e2=Entry(root,textvariable=var_F)
e2.grid(row=1,column=1)
def my_CtoF():
e2.delete(0,"end")
ec=float(eval(e1.get()))
f=ec*9/5+32
e2.insert(0,str(f))
def my_FtoC():
e1.delete(0,"end")
ef=float(eval(e2.get()))
c=5/9*(ef-32)
e1.insert(0,str(c))
def my_clear():
e1.delete(0,"end")
e2.delete(0,"end")
b1=Button(root,text="C转F",width = 10,command=my_CtoF)
b1.grid(row=2,column=0,sticky=W)
b2=Button(root,text="F转C",width = 10,command=my_FtoC)
b2.grid(row=2,column=1,sticky=W)
b3=Button(root,text="重 置",width = 10,command=my_clear)
b3.grid(row=3,column=0,sticky=W)
b4=Button(root,text="退 出",width = 10,command=root.quit)
b4.grid(row=3,column=1,sticky=W)
root.mainloop()