SO i had to make a temp converter. I have made the whole application and i can convert from cel to fah but i dont understand why i cant convert from fah to cel although i have written the code to do so. i am not sure is it the string var or is it just the if statements i have tried changing alot but i need help now.
from Tkinter import*
def convert():
fahTemp = fahTempVar.get()
celTemp = celTempVar.get()
if celTemp == 0:
fahToCel = ((fahTemp - 32) * (5/9))
celTempVar.set(fahToCel)
if fahTemp == 0:
celToFah = (celTemp * 9/5 + 32)
fahTempVar.set(celToFah)
def reset():
top = Toplevel(padx=50, pady=50)
top.grid()
message = Label(top, text = "Reset Complete")
button = Button(top, text="OK", command=top.destroy)
message.grid(row = 0, padx = 5, pady = 5)
button.grid(row = 1, ipadx = 10, ipady = 10, padx = 5, pady = 5)
fahTempVar.set(0)
celTempVar.set(0)
###MAIN###
root = Tk()
root.title("Temperature Converter")
mainframe = Frame(root)
mainframe.grid()
celTempVar = IntVar()
##celTempVar.set()
fahTempVar = IntVar()
##fahTempVar.set()
titleLabel = Label (mainframe, text = "Celcius/Fahrenheit Temperature", font = ("Arial", 20, "bold"), justify = CENTER)
titleLabel.grid(row = 1, column = 1, columnspan = 3, pady = 10, padx = 20)
celLabel = Label (mainframe, text = "Celcius: ", font = ("Arial", 16), fg = "red")
celLabel.grid(row = 2, column = 1, pady = 10, sticky = NW)
fahLabel = Label (mainframe, text = "Fahrenheit: ", font = ("Arial", 16), fg = "blue")
fahLabel.grid(row = 3, column = 1, pady = 10, sticky = NW)
celEntry = Entry (mainframe, width = 10, bd = 5, textvariable = celTempVar)
celEntry.grid(row = 2, column = 1, pady = 10, sticky = NW, padx = 125 )
fahEntry = Entry (mainframe, width = 10, bd = 5, textvariable = fahTempVar)
fahEntry.grid(row = 3, column = 1, pady = 10, sticky = NW, padx = 125 )
convertButton =Button (mainframe, text = "Convert", font = ("Arial", 8, "bold"), relief = RAISED, bd=5, justify = CENTER, highlightbackground = "red", overrelief = GROOVE, activebackground = "green", activeforeground="blue", command = convert)
convertButton.grid(row = 4, column = 1, ipady = 8, ipadx = 12, pady = 5, sticky = NW, padx = 55)
resetButton = Button (mainframe, text = "Reset", font = ("Arial", 8, "bold"), relief = RAISED, bd=5, justify = CENTER, highlightbackground = "red", overrelief = GROOVE, activebackground = "green", activeforeground="blue", command = reset)
resetButton.grid(row = 5, column = 1,ipady = 8, ipadx = 12, pady = 5, sticky = NW)
root.mainloop()

New Topic/Question
Reply




MultiQuote
.




|