mcalla at home.com
Sun Apr 23 03:36:55 CEST 2000
Thanks, John. I see how to do it now.
<johngrayson at home.com> wrote in message news:8dship$83j$1 at nnrp1.deja.com...
> In article <ZiYL4.110745$8S2.1383832 at news1.rdc1.tn.home.com>,
> "Mike Callahan" <mcalla at home.com> wrote:
> > How does one change an OptionMenu widget's list? I know that you can
> do this
> > easily using the PMW widget, but I would like to stay with basic
> > widgets to keep the code as small as possible. I could not find any
> > in the code and I could not find any examples in either the online
> > documentation or the new book on Tkinter.
> I didn't expand on Tkinter's OptionMenu class too much in _Python and
> Tkinter Programming_, since using Pmw's version is usually more
> convenient. The problem is that you really have to 'roll your own'
> to do much with the vanilla widget.
> However, if you insist, here is some sample code to manipulate
> Tkinter's OptionMenu:
> from Tkinter import *
> root = Tk()
> class setit:
> def __init__(self, var, value):
> self.__value = value
> self.__var = var
> def __call__(self, *args):
> class OptionM:
> def __init__(self,parent):
> self.var = StringVar()
> self.opt_menu = OptionMenu(parent, self.var, 'Stockbroker',
> 'Quantity Surveyor', 'Church Warden',
> 'BRM' )
> self.opt_menu.pack(anchor=W, padx=20, pady=30)
> Button(parent, text='Add item', command=self.addItem).pack()
> Button(parent, text='Change items',
> def addItem(self):
> command=setit(self.var, 'Dinsdale'))
> def changeItems(self):
> self.opt_menu["menu"].delete(0, END)
> for item in ['Passion fruit','Loganberries','Mangoes in syrup',
> command=setit(self.var, item))
> om = OptionM(root)
> A bit crude, but it's a start. Use Pmw if you can!
> Sent via Deja.com http://www.deja.com/
> Before you buy.
More information about the Python-list