Inserting this line: self.listbox2.InsertItems([choice],0)
in your OnListBox1 method after your if/then/else statement puts the item you select in ListBox1 appear in ListBox2. You have to force choice into a list, otherwise it will insert each individual letter in the string into the box one at a time. Docs: http://wxwidgets.org/manuals/stable/wx_wxlistbox.html#wxlistbox Now, admittedly, this is on a Windows XP machine, but I don't think that such basic functionality would be different between platforms. On Nov 28, 2007 12:24 PM, John Gerdeman <[EMAIL PROTECTED]> wrote: > Hello, > > I'm trying to create a gui using wxpython on ubuntu 6.10 (read, that > some functions of wx differ on different OS). > > I have two Listbox items, Listbox1 and Listbox2. I want to update > Listbox2 according to the choice made in Listbox1. > I already looked at the wx API doc, but only found methods to insert > items or (de)select. > > I know I can update a textctrl, but I need a way to make a choice based > on the first. > > Here a Minimal example: > > #!/usr/bin/python > > import wx > > class MyFrame(wx.Frame): > def __init__(self, parent, id, title): > wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, > (550, 350)) > > self.listbox1_items = [ 'item1', 'item2'] > self.listbox2_items = ['select a item from the right'] > > hbox1 = wx.BoxSizer(wx.HORIZONTAL) > vbox = wx.BoxSizer(wx.VERTICAL) > > panel = wx.Panel(self, -1) > > self.listbox1 = wx.ListBox(panel, 1, wx.DefaultPosition, (170, > 130), self.listbox1_items, wx.LB_SINGLE) > self.listbox1.SetSelection(0) > self.listbox2 = wx.ListBox(panel, 2, wx.DefaultPosition, (170, > 130), self.listbox2_items, wx.LB_SINGLE) > self.listbox2.SetSelection(0) > hbox1.Add(self.listbox1, 0, wx.TOP, 40) > hbox1.Add(self.listbox2, 0, wx.TOP, 40) > vbox.Add(hbox1, 0, wx.ALIGN_CENTRE) > panel.SetSizer(vbox) > > self.Bind(wx.EVT_LISTBOX, self.OnListBox1, id=1) > self.Bind(wx.EVT_LISTBOX, self.OnListBox2, id=2) > > def OnListBox1(self, event): > index = event.GetSelection() > choice = self.listbox1_items[index] > print "You chose " + str(choice) > if choice == 'item1': > ret = ['choice1', 'choice2'] > elif choice == 'item2': > ret = ['choice3', 'choice4'] > else: > ret = ['Ooops'] > print "Now I somehow need a way to pass to self.listbox2 I > can set > self.listbox2_items to ret, but self.listbox2 doesn't get updated" > print ret > def OnListBox2(self, event): > return True > > > class MyApp(wx.App): > def OnInit(self): > frame = MyFrame(None, -1, 'minexample.py') > frame.Centre() > frame.Show(True) > return True > > app = MyApp(0) > app.MainLoop() > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > >
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor