Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | """ |
2 | OptionMenu widget modified to allow dynamic menu reconfiguration | |
3 | and setting of highlightthickness | |
4 | """ | |
5 | from Tkinter import OptionMenu | |
6 | from Tkinter import _setit | |
7 | import copy | |
8 | ||
9 | class DynOptionMenu(OptionMenu): | |
10 | """ | |
11 | unlike OptionMenu, our kwargs can include highlightthickness | |
12 | """ | |
13 | def __init__(self, master, variable, value, *values, **kwargs): | |
14 | #get a copy of kwargs before OptionMenu.__init__ munges them | |
15 | kwargsCopy=copy.copy(kwargs) | |
16 | if 'highlightthickness' in kwargs.keys(): | |
17 | del(kwargs['highlightthickness']) | |
18 | OptionMenu.__init__(self, master, variable, value, *values, **kwargs) | |
19 | self.config(highlightthickness=kwargsCopy.get('highlightthickness')) | |
20 | #self.menu=self['menu'] | |
21 | self.variable=variable | |
22 | self.command=kwargs.get('command') | |
23 | ||
24 | def SetMenu(self,valueList,value=None): | |
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 | if value: | |
35 | self.variable.set(value) |