Heat index calculator program - a Tkinter app
The app uses heat index formula for degree celcius from Wikipedia.
code
#!/usr/bin/python3
import tkinter as tk
from tkinter import ttk
from tkinter import font
from tkinter import *
def heatIndex(temperature,RH):
c1 = -8.784_694_755_56
c2 = 1.611_394_11
c3 = 2.338_548_838_89
c4 = -0.146_116_05
c5 = -0.012_308_094
c6 = -0.016_424_827_7778
c7 = 2.211_732e-3
c8 = 7.2546e-4
c9 = -3.582e-6
HI = c1 + c2 * temperature
HI += c3 * RH + c4 * temperature * RH + c5 * temperature**2
HI += c6 * RH**2 + c7 * temperature**2 * RH
HI += c8 * temperature * RH**2 + c9 * temperature**2 * RH**2
return HI
# this is the function called when the button is clicked
def btnClickFunction():
print('clicked')
try:
temp = float(getTempBoxValue())
humid = float(getHumidBoxValue())
except ValueError:
print("input is not number")
return
print(f't={temp} h={humid}')
hiVal = heatIndex(temperature=temp,RH=humid)
print(f'hi={hiVal}')
hiLableText.set(f'{hiVal:.2f}')
# this is a function to get the user input from the text input box
def getTempBoxValue():
userInput = tInput.get()
return userInput
# this is a function to get the user input from the text input box
def getHumidBoxValue():
userInput = hInput.get()
return userInput
root = Tk()
entryItem_Font = font.Font(size=16)
# This is the section of code which creates the main window
root.geometry('550x250')
root.configure(background='#F0F8FF')
root.title('Heat Index Calculator')
# This is the section of code which creates a button
Button(root, text='calculate', bg='#F0F8FF', font=('arial', 12, 'normal'), command=btnClickFunction).grid(row=0,column=2)
# This is the section of code which creates the a label
Label(root, text='Temperature (C)', bg='#F0F8FF', font=('arial', 12, 'normal')).grid(row=0,column=0)
# This is the section of code which creates the a label
Label(root, text='%RH', bg='#F0F8FF', font=('arial', 12, 'normal')).grid(row=1,column=0)
# This is the section of code which creates a text input box
tInput=Entry(root,font=entryItem_Font)
tInput.grid(row=0,column=1,padx=10,pady=10)
# This is the section of code which creates a text input box
hInput=Entry(root,font=entryItem_Font)
hInput.grid(row=1,column=1,padx=10,pady=10)
# This is the section of code which creates the a label
Label(root, text='Heat Index', bg='#F0F8FF', font=('arial', 12, 'normal')).grid(row=2,column=0,pady=30)
# This is the section of code which creates the a label
hiLableText = StringVar()
hiLabel = Label(root, textvariable=hiLableText, bg='#F0F8FF', font=('arial', 34, 'normal'))
hiLabel.grid(row=2,column=1,sticky=W)
hiLableText.set("NNNN")
root.mainloop()