2001-10-26 03:49:14 -03:00
|
|
|
"""
|
|
|
|
OptionMenu widget modified to allow dynamic menu reconfiguration
|
2001-11-03 10:55:47 -04:00
|
|
|
and setting of highlightthickness
|
2001-10-26 03:49:14 -03:00
|
|
|
"""
|
2008-05-16 12:48:15 -03:00
|
|
|
from tkinter import OptionMenu
|
|
|
|
from tkinter import _setit
|
2001-11-03 10:55:47 -04:00
|
|
|
import copy
|
2001-10-26 03:49:14 -03:00
|
|
|
|
|
|
|
class DynOptionMenu(OptionMenu):
|
|
|
|
"""
|
2001-11-03 10:55:47 -04:00
|
|
|
unlike OptionMenu, our kwargs can include highlightthickness
|
2001-10-26 03:49:14 -03:00
|
|
|
"""
|
|
|
|
def __init__(self, master, variable, value, *values, **kwargs):
|
2001-11-03 10:55:47 -04:00
|
|
|
#get a copy of kwargs before OptionMenu.__init__ munges them
|
|
|
|
kwargsCopy=copy.copy(kwargs)
|
|
|
|
if 'highlightthickness' in kwargs.keys():
|
|
|
|
del(kwargs['highlightthickness'])
|
2001-10-26 03:49:14 -03:00
|
|
|
OptionMenu.__init__(self, master, variable, value, *values, **kwargs)
|
2001-11-03 10:55:47 -04:00
|
|
|
self.config(highlightthickness=kwargsCopy.get('highlightthickness'))
|
2001-10-26 03:49:14 -03:00
|
|
|
#self.menu=self['menu']
|
|
|
|
self.variable=variable
|
|
|
|
self.command=kwargs.get('command')
|
2002-12-31 12:03:23 -04:00
|
|
|
|
2001-10-29 04:05:34 -04:00
|
|
|
def SetMenu(self,valueList,value=None):
|
2001-10-26 03:49:14 -03:00
|
|
|
"""
|
|
|
|
clear and reload the menu with a new set of options.
|
|
|
|
valueList - list of new options
|
2002-12-31 12:03:23 -04:00
|
|
|
value - initial value to set the optionmenu's menubutton to
|
2001-10-26 03:49:14 -03:00
|
|
|
"""
|
|
|
|
self['menu'].delete(0,'end')
|
|
|
|
for item in valueList:
|
|
|
|
self['menu'].add_command(label=item,
|
|
|
|
command=_setit(self.variable,item,self.command))
|
2001-10-29 04:05:34 -04:00
|
|
|
if value:
|
|
|
|
self.variable.set(value)
|