0

I'm using Tkinter in python and have a dropdown menu with various choices and a button. I want the command function of this button to change based on the selection of the dropdown menu. However, it seems that my initial setting of the selection variable does not change. How do I resolve this? Currently, it seems that my initial setting of clicked is causing the button to be configured one way and it does not change based on the user selection.

def get_chosen_opp(clicked):
    return clicked.get()

clicked=StringVar() #this will be the chosen team
drop=OptionMenu(self,clicked,"Catholic","Coast Guard","Maine Maritime","Merchant Marine","Norwich","Springfield","WPI","Non-Conference Opponent")
clicked.set("Non-Conference Opponent")
drop.place(relx=.5,rely=.35,anchor='n',relheight=.1,relwidth=.4)

lower_frame=tk.Frame(self,bd=5,bg='#252122')  
lower_frame.place(relx=.5,rely=.6,relwidth=0.35,relheight=.1,anchor='n')
continue_button=tk.Button(lower_frame,text='See Chart',font=30,bg='#7F120E')

#set custom stats if non-conference oponent
selection=get_chosen_opp(clicked)
if selection=="Non-Conference Opponent":
    continue_button.config(command=lambda:controller.show_label(set_nc_stats))
else:
    continue_button.config(command=lambda:controller.show_label(show_chart))

continue_button.place(relheight=1,relwidth=1)
hw21
  • 1
  • 1
  • As it stands it will not work. First you have to understand [Event-driven programming](https://stackoverflow.com/a/9343402/7414759). Move all statements, except `... get_chosen_opp` and `.place(...`, starting at `#set custom stats ...` into `def get_chosen_opp(` and bind this function to `OptionMenu(.... command=`. – stovfl Mar 20 '20 at 21:26
  • That helped so much! Thank you! – hw21 Mar 20 '20 at 22:44

0 Answers0