blob: bc716ed2727eaacc34d645519caee59efe1e2f95 [file] [log] [blame]
Steven M. Gavaf126bcb2001-10-26 06:49:14 +00001##---------------------------------------------------------------------------##
2##
Steven M. Gavac034b472001-11-03 14:55:47 +00003## idle - modified OptionMenu widget
Steven M. Gavaf126bcb2001-10-26 06:49:14 +00004## elguavas
5##
6##---------------------------------------------------------------------------##
7"""
8OptionMenu widget modified to allow dynamic menu reconfiguration
Steven M. Gavac034b472001-11-03 14:55:47 +00009and setting of highlightthickness
Steven M. Gavaf126bcb2001-10-26 06:49:14 +000010"""
11from Tkinter import OptionMenu
12from Tkinter import _setit
Steven M. Gavac034b472001-11-03 14:55:47 +000013import copy
Steven M. Gavaf126bcb2001-10-26 06:49:14 +000014
15class DynOptionMenu(OptionMenu):
16 """
Steven M. Gavac034b472001-11-03 14:55:47 +000017 unlike OptionMenu, our kwargs can include highlightthickness
Steven M. Gavaf126bcb2001-10-26 06:49:14 +000018 """
19 def __init__(self, master, variable, value, *values, **kwargs):
Steven M. Gavac034b472001-11-03 14:55:47 +000020 #get a copy of kwargs before OptionMenu.__init__ munges them
21 kwargsCopy=copy.copy(kwargs)
22 if 'highlightthickness' in kwargs.keys():
23 del(kwargs['highlightthickness'])
Steven M. Gavaf126bcb2001-10-26 06:49:14 +000024 OptionMenu.__init__(self, master, variable, value, *values, **kwargs)
Steven M. Gavac034b472001-11-03 14:55:47 +000025 self.config(highlightthickness=kwargsCopy.get('highlightthickness'))
Steven M. Gavaf126bcb2001-10-26 06:49:14 +000026 #self.menu=self['menu']
27 self.variable=variable
28 self.command=kwargs.get('command')
29
Steven M. Gava41a85322001-10-29 08:05:34 +000030 def SetMenu(self,valueList,value=None):
Steven M. Gavaf126bcb2001-10-26 06:49:14 +000031 """
32 clear and reload the menu with a new set of options.
33 valueList - list of new options
34 value - initial value to set the optionmenu's menubutton to
35 """
36 self['menu'].delete(0,'end')
37 for item in valueList:
38 self['menu'].add_command(label=item,
39 command=_setit(self.variable,item,self.command))
Steven M. Gava41a85322001-10-29 08:05:34 +000040 if value:
41 self.variable.set(value)