Tkinter how to make a dynamic optionmenu without using a dictionary Tkinter how to make a dynamic optionmenu without using a dictionary tkinter tkinter

Tkinter how to make a dynamic optionmenu without using a dictionary


Ok, so I found the answer after continuing to work with it to help out anyone in future having the same problem. I changed self.TAB_OPTION to:

self.TAB_OPTION(tab, self.tabsvar, *self.list_of_tabs, command=self.read_columns)

By adding this, I had to pass in a variable into self.read_columns, as adding the command automatically passes the value the user selected in the first optionmenu. So, I changed self.read_columns to:

def read_columns(self, board):    sheet = board    #sheet = self.tabs_var.get()

I also took out the line shown to be commented above, so it received the value that was selected in the first optionmenu from the TAB_OPTION rather than reading what is selected from the GUI. I also added in:

self.VALUES_OPTION['menu'].delete(0, 'end')for item in values:    self.VALUES_OPTION['menu'].add_command(label=item)

at the end of the read_columns function so it would regenerate the values for the second optionmenu. It deletes all of the previous values, then adds each value that had been read from the excel in by iterating through the array. I no longer needed the return value at the end of the function. I hope this helps other confused coders :)