cpython/Lib/idlelib/dynOptionMenuWidget.py

36 lines
1.3 KiB
Python
Raw Normal View History

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