0

So I am trying to Trace a variable to invoke a callback everytime it changes, however, the trace function always triggers. What's the problem? Here is my code:

options = ["Today", "History", "Options"]
chosen = StringVar(window)
chosen.set(options[0])
menu = OptionMenu(window, chosen, *options)
chosen.trace("w", update_gui())

Edit: this is not a dupplicate, the other question doesn't answer mine

Vynokris
  • 31
  • 1
  • 6
  • Please add a stringvar and an optionmenu to your code that we can see what happens without trying to rebuild your error. – Thingamabobs Aug 25 '20 at 14:54
  • Remove the brackets for the function and try? `day_chosen.trace("w", update_gui)` – Delrius Euphoria Aug 25 '20 at 14:56
  • Just added a stringvar, an option menu and a list for the optionmenu's values. If I remove the brackets, It outputs this error: `update_gui() takes 0 positional arguments but 3 were given` – Vynokris Aug 25 '20 at 15:13
  • Then why are you not passing in the arguments like `day_chosen.trace("w", lambda: update_gui(param1,param2,param3)` – Delrius Euphoria Aug 25 '20 at 16:20
  • Well if I do this there is a new error: `TypeError: () takes 0 positional arguments but 3 were given` I also tried doing this: `day_chosen.trace("w", update_gui)` And put 3 random values in the initiation of my function like this: `def update_gui(a,b,c)` But now whenever I change the value of the "chosen" variable, the trace function always triggers the update_gui function. – Vynokris Aug 25 '20 at 20:02

0 Answers0