'First tkinter project ,trying to find a way to make my tkinter buttons change boolean values for future if statements

I couldnt seem to find a way to make my program realise that ive selected a button, so i changed the function of the celcius to farenheit to try to make it change a boolean value to determine what conversion the program is doing

def celcius_to_farenheit(_event = None):
    c_to_f = True
    f_to_c = False 

the idea being later i can use if statments later in the end result function to find what conversion its doing and display results in the status bar

def end_result():
    if c_to_f == True:
        converted_temperature = (valid_temperature * 9/5) + 32
        label_status.configure(text = converted_temperature, fg = "Orange")

currently i seem to have functions running without me pressing buttons as well, when start the program it immediatly goes to the error message ive created for input muct be numeric even if i havent pressed the celcius to farenheit button.

Any help regarding how to propely have my celcius to farenheit and farenheit to celcius buttons confirm its a float and change a value to use for determining which calculation its using would be helpfull. Knowing why the error message comes up automatically is a bonus.

Below is my code thank you for your time and help.




import sys
from tkinter import *
from tkinter.tix import *
  
c_to_f = True

def clear_reset(_event = None):
    entry_temperature.delete(0, END)
    label_status.configure(text = "All data cleared", fg = "Orange")


def end_program(_event = None):
    sys.exit()
    
def convert_temp(_event = None):
    try: 
        valid_temperature = float(entry_temperature.get())
    except:
        label_status.configure(text = "Input must be numeric", fg = "Orange")
        
def end_result():
    if c_to_f == True:
        converted_temperature = (valid_temperature * 9/5) + 32
        label_status.configure(text = converted_temperature, fg = "Orange")

def celcius_to_farenheit(_event = None):
    c_to_f = True
    f_to_c = False
     
    
def farenheit_to_celcius(_event = None):
    f_to_c = True
    c_to_f = False


window = Tk()
window.geometry("550x200")
window.resizable(False, False)
window.title("Temperature Conversion")




tooltip = Balloon(window)

label_input_Temperature = Label(text = "Temperature",fg = "Green")
label_input_Temperature.grid(row= 0, column=0)


entry_temperature = Entry(window, bg = "light blue" )
entry_temperature.grid(row=0, column=1)



temp_button_c_to_f = Button(window, text = "Celcius to Farenheit", command = celcius_to_farenheit)
temp_button_c_to_f.grid(row = 1, column=0)
window.bind('<Shift-c>', celcius_to_farenheit)
tooltip.bind_widget(temp_button_c_to_f, msg = "Shift + C")


temp_button_f_to_c = Button(window, text = "Farenheit to Celcius")
temp_button_f_to_c.grid(row = 1, column = 1 )


conversion_button = Button(window, text = "Convert", command = convert_temp)
conversion_button.grid(row = 2, column = 0,padx =0 )
window.bind('<Enter>', convert_temp)
tooltip.bind_widget(conversion_button, msg = "Enter")



clear_button = Button(window, text = "Clear", command = clear_reset)
clear_button.grid(row = 2, column = 1)  
window.bind('<Control-c>', clear_reset)
tooltip.bind_widget(clear_button, msg = "Ctrl + C")

exit_button = Button(window, text = "Exit")
exit_button.grid(row = 2, column = 2, padx = 20, pady = 20)  
window.bind('<Control-x>', end_program)
tooltip.bind_widget(exit_button, msg = "Ctrl + X")

label_status = Label(window, width = 50, borderwidth = 2, relief= RIDGE,bg= "Grey" )
label_status.grid(row = 4, column = 1)
tooltip.bind_widget(label_status, msg = "Displays results / error messages")
label_status.configure(text = "Enter in your temperature and select your conversion", fg = "Orange")



window.mainloop()



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source