0001 """ 0002 OptionMenu widget modified to allow dynamic menu reconfiguration 0003 and setting of highlightthickness 0004 """ 0005 from Tkinter import OptionMenu 0006 from Tkinter import _setit 0007 import copy 0008 0009 class DynOptionMenu(OptionMenu): 0010 """ 0011 unlike OptionMenu, our kwargs can include highlightthickness 0012 """ 0013 def __init__(self, master, variable, value, *values, **kwargs): 0014 #get a copy of kwargs before OptionMenu.__init__ munges them 0015 kwargsCopy=copy.copy(kwargs) 0016 if 'highlightthickness' in kwargs.keys(): 0017 del(kwargs['highlightthickness']) 0018 OptionMenu.__init__(self, master, variable, value, *values, **kwargs) 0019 self.config(highlightthickness=kwargsCopy.get('highlightthickness')) 0020 #self.menu=self['menu'] 0021 self.variable=variable 0022 self.command=kwargs.get('command') 0023 0024 def SetMenu(self,valueList,value=None): 0025 """ 0026 clear and reload the menu with a new set of options. 0027 valueList - list of new options 0028 value - initial value to set the optionmenu's menubutton to 0029 """ 0030 self['menu'].delete(0,'end') 0031 for item in valueList: 0032 self['menu'].add_command(label=item, 0033 command=_setit(self.variable,item,self.command)) 0034 if value: 0035 self.variable.set(value) 0036
Generated by PyXR 0.9.4