0

The following code creates an OptionMenu with two options: "A" or "B":

from Tkinter import *
root = Tk()

clicked = StringVar(root)
clicked.set("Select")

def function(x):

  if x == "A":
      doSomething()

  else:
      donNothing()

drop = OptionMenu(root, clicked, "A", "B", command=function)
drop.pack()

root.mainloop()

In this code, it assumes that the data table has only columns A & B. However, the data tables I import all have a different number of columns (e.g. one dataset may have columns A, B, C, D, E whereas another dataset may have columns A, B, C).

How can I change the option menu's number of drop down options depending on the number of columns my data has (e.g. if one dataset has 3 columns, the option menu will have 3 options whereas if another dataset has 5 columns, the option menu will have 5 options)?

  • Try `drop = OptionMenu(root, clicked, *dataset, command=function)` where `dataset` is `list` or `tuple` of the items from the data table. – acw1668 Jun 17 '20 at 03:17
  • Does this answer your question? [dropdown-option-to-show-subset-of-dataframe-tkinter](https://stackoverflow.com/questions/59890350) – stovfl Jun 17 '20 at 08:14

0 Answers0