I am stuck
I am changing the content of an OptionMenu with the refresh() function and it works fine in case A but when in case B where I change it to a callback the OptionMenu stops working. Clicking on an option no longer selects it.
Any idea what makes it so?
Case A:
import tkinter as tk
root = tk.Tk()
cvar = tk.StringVar(root)
cvar.set("-")
optionlist = ('one', 'two', 'three')
def refresh(contentlist):
optionmenu['menu'].delete(0, 'end')
for content in contentlist:
optionmenu['menu'].add_command(label=content, command=tk._setit(cvar, content))
def doNothing():
return
optionmenu = tk.OptionMenu(root, cvar, *optionlist, command=doNothing)
optionmenu.pack()
refresh(optionlist)
root.mainloop()
Case B:
def contentcallback(var, name):
tk._setit(var, name)
def refresh(contentlist):
optionmenu['menu'].delete(0, 'end')
for content in contentlist:
optionmenu['menu'].add_command(label=content, command=contentcallback(cvar, content))