2017年10月2日 星期一

Tkinter 攝氏溫度轉為華氏溫度



from tkinter import *
from tkinter.messagebox import *


def show_answer():
   # fahrenheit = (celsius * 1.8) + 32         
   Ans =  (float(num1.get()) * 1.8 + 32 )
   Ans = "{:.3f}".format(Ans) 
   blank1.delete('0', END)
   blank1.insert(0, Ans)


main = Tk()
main.title("Tkinter 攝氏溫度轉為華氏溫度  ")

Label(main, text = "輸入攝氏溫度 :").grid(row=0)
Label(main, text = " 華氏溫度 =").grid(row=2)


num1 = Entry(main)
blank1 = Entry(main)

num1.grid(row=0, column=1)
blank1.grid(row=2, column=1)

Button(main, text='離開', command=main.destroy).grid(row=4, column=0, sticky=W, pady=4)
Button(main, text='轉換', command=show_answer).grid(row=4, column=1, sticky=W, pady=4)

mainloop()

===============================================
文字方式
===============================================

# 使用者輸入攝氏溫度
# 接收使用者輸入
celsius = float(input('輸入攝氏溫度: '))
# 計算華氏溫度
fahrenheit = (celsius * 1.8) + 32
print('%0.1f 攝氏溫度轉為華氏溫度為 %0.1f ' %(celsius,fahrenheit))


輸入攝氏溫度: 45.6
45.6 攝氏溫度轉為華氏溫度為 114.1 
>>> 



沒有留言:

張貼留言

2024年4月24日 星期三 Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --2

 2024年4月24日 星期三 Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --2 AngularJS 實例 <!DOCTYPE html> <html> <head> &...