0

I have a list of options:

OPTIONS = [
 "Algorithm 1",
 "Algorithm 2"
]

I would like to link this function below to the option Algorithm 1:

def combine_funcs(*funcs):
    def combined_func(*args, **kwargs):
        for f in funcs:
            f(*args, **kwargs)

    return combined_func

Heres what I've tried doing:

 SelectedOptions = StringVar(top)
 SelectedOptions.set(OPTIONS[0])
 typeOption = OptionMenu(top, SelectedOptions, *OPTIONS)

Here's my start button:

 self.Button1 = tk.Button(top, command = functionschoose()) 
 self.Button1.place(relx=0.839, rely=0.917, height=35, width=62)

Here's my function that selects which Algorithm to run

 def functionschoose():
         if SelectedOptions.get() == "Algorithm 1":
             return combine_funcs(popup_bonus, callback)

         else:
             print "second func" # this is still empty because the algorithm has not been implemented yet.

For now the Algorithm gotten using .get() always seem to be Algorithm 1

I believe this is due to SelectedOptions.set(OPTIONS[0])

Is there any way to follow the real time selection of the user?

Thanks.

John
  • 51
  • 1
  • 4
  • 1
    *"... only invoking ... when clicks start button?"*: Add a `command=...` to the `Button` get the `SelectedOptions` on invoking and call the desired function. – stovfl Mar 21 '19 at 13:51
  • @stovfl How do I first link the functions to the option Algorithm 1 so that I can call the function? – John Mar 21 '19 at 15:50
  • 1
    *"first link the functions to the option"*: You don't, simple condition `if SelectedOptions.get == 'Alg...1':` – stovfl Mar 21 '19 at 16:05
  • @stovfl SelectedOptions.get() seems to be always getting the Algorithm 1 and not Algorithm 2. I believe this is because of SelectedOptions.set(OPTIONS[0]) . Is there any way to work around the .set function? – John Mar 21 '19 at 16:39
  • Possible duplicate of [Changing the options of a OptionMenu when clicking a Button](https://stackoverflow.com/questions/17580218/changing-the-options-of-a-optionmenu-when-clicking-a-button) – stovfl Mar 21 '19 at 17:29
  • 1
    This `command = functionschoose()` is the culprit. Read [Why is Button parameter “command” executed when declared?](https://stackoverflow.com/questions/5767228/why-is-button-parameter-command-executed-when-declared) – stovfl Mar 21 '19 at 17:41

0 Answers0