blob: 48a08865ec6b36d7c527a2e4d647d8fd56c7ebee [file] [log] [blame]
Steven M. Gavaf126bcb2001-10-26 06:49:14 +00001##---------------------------------------------------------------------------##
2##
3## idle - tkinter OptionMenu widget modified to allow dynamic
4## reconfiguration of menu.
5## elguavas
6##
7##---------------------------------------------------------------------------##
8"""
9OptionMenu widget modified to allow dynamic menu reconfiguration
10"""
11from Tkinter import OptionMenu
12from Tkinter import _setit
13
14class DynOptionMenu(OptionMenu):
15 """
16 OptionMenu widget that allows dynamic menu reconfiguration
17 """
18 def __init__(self, master, variable, value, *values, **kwargs):
19 OptionMenu.__init__(self, master, variable, value, *values, **kwargs)
20 #self.menu=self['menu']
21 self.variable=variable
22 self.command=kwargs.get('command')
23
24 def SetMenu(self,valueList,value):
25 """
26 clear and reload the menu with a new set of options.
27 valueList - list of new options
28 value - initial value to set the optionmenu's menubutton to
29 """
30 self['menu'].delete(0,'end')
31 for item in valueList:
32 self['menu'].add_command(label=item,
33 command=_setit(self.variable,item,self.command))
34 self.variable.set(value)