your textI am making a Custom Scientific Calculator in tkinter Python and I want a button to reset everything in the program to how it was when the program first started. It is heavily unfinished but I am doing it one step at a time and so far I have not been able to find out how to reset my OptionMenu. I am using VSCode with Python and Pylance extensions.
This is the code I have that is relevant to the problem and if you would like me to copy and paste the entire script I can.
#Creates the variable for the option menu
opmOneDefault = StringVar(frm)
opmOneDefault.set("FORMULA")
opmOneVariable = tk.StringVar(value=opmOneDefault)
#This is where functions are defined
def make_formula_option_menu():
formula_option_menu = OptionMenu(frm, opmOneVariable, opmOneDefault,
"Moles of A to Grams of B",
"Moles of A to Moles of B",
"Grams of A to Grams of B"
)
formula_option_menu.grid(column=0, row=8, sticky=SW)
def reset_all():
opmOneVariable.set(opmOneDefault)
reset_button = ttk.Button(frm,
text="Reset",
command=reset_all)
reset_button.grid(column=0, row=4, sticky=SW)
formula_option_menu = OptionMenu(frm, opmOneDefault,
"Moles of A to Grams of B",
"Moles of A to Moles of B",
"Grams of A to Grams of B"
)
#This is where the OptionMenus are told where to be
formula_option_menu.grid(column=0, row=8, sticky=SW)
I have Googled my problem but have not found a effective solution. I have tried the reset_all function with various different commands including: setvar(), setattr(), optionclear, and other similar ways but am stuck on this. I was expecting one of these to work but obviously they didn't reset the drop down box to how it was before I clicked and chose an option.