Skip to content Skip to sidebar Skip to footer

Tkinter - Only Show Filled Values Of An Array In A Optionmenu

I've the following code: self.array_lt = ['foo', 'bar', '', 'moo'] var = StringVar() self.menult = OptionMenu(randomwindow, var, *self.array_lt) self.menult.config(width=30) self.m

Solution 1:

You can use filter with None as the filter function to filter out values that would evaluate to False when interpreted as a boolean:

>>> filter(None, ["1", 0, " ", "", None, True, False, "False"])
['1', ' ', True, 'False']

Use this when you pass the list to the OptionMenu

self.menult = OptionMenu(randomwindow, var, *filter(None, self.array_lt))

Post a Comment for "Tkinter - Only Show Filled Values Of An Array In A Optionmenu"