Steven M. Gava | f126bcb | 2001-10-26 06:49:14 +0000 | [diff] [blame] | 1 | ##---------------------------------------------------------------------------## |
| 2 | ## |
| 3 | ## idle - tkinter OptionMenu widget modified to allow dynamic |
| 4 | ## reconfiguration of menu. |
| 5 | ## elguavas |
| 6 | ## |
| 7 | ##---------------------------------------------------------------------------## |
| 8 | """ |
| 9 | OptionMenu widget modified to allow dynamic menu reconfiguration |
| 10 | """ |
| 11 | from Tkinter import OptionMenu |
| 12 | from Tkinter import _setit |
| 13 | |
| 14 | class 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) |