[wxPython-users] combobox problem

C M cmpython at gmail.com
Mon Nov 19 13:48:22 PST 2007


On Nov 19, 2007 4:23 PM, Thippana, Prasoonadevi <pthippan at mc.com> wrote:

>  Hi,
>
> Can somebody help me with the combobox problem.When I start the my GUI
> application, it should upload all the directories from the path into the
> combo box.
>
> I created 2 directories in my path. When I run this program, it Sets up
> one directory and when I click it, it just disappears.
>
> Thanks in advance for the help.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wxPython-users-unsubscribe at lists.wxwidgets.org
> For additional commands, e-mail: wxPython-users-help at lists.wxwidgets.org
>

Your program was adding each entry to the combobox as the displayed value
in the textbox but not creating a list for the combobox to hold all the
items.  So
you only saw the last one added.

You can just append each new entry to a growing list and then use
comboBox.SetItems(list) as below...

import wx
import os, sys
import string
import re
import wx.lib.dialogs

class MyFrame1(wx.Frame):
        def __init__(self, parent, id, title):
            wx.Frame.__init__(self, parent,-1,title,wx.DefaultPosition,
wx.Size(450,200))

            self.mainpa =3D wx.Panel(self,-1,wx.DefaultPosition,
wx.DefaultSize)
            self.samplelist =3D []

            self.combo1=3D wx.ComboBox(self.mainpa,-1,"",(120,70),(105,-1),
self.samplelist,
               wx.CB_DROPDOWN)
            path=3Dos.getcwd()
            for entry in os.listdir(path):
                    if os.path.isdir(entry):
                            print 'entry %s' % entry
                            self.samplelist.append(entry)
                            self.combo1.SetItems(self.samplelist)

            ok =3D wx.Button(self.mainpa, -1, 'Ok',wx.Point(300,100))

class MyApp(wx.App):
    def OnInit(self):
        frame =3D MyFrame1(None, -1, 'Make Directory Structure')
        frame.Show(True)
        self.SetTopWindow(frame)
        return True


app =3D MyApp(0)
app.MainLoop()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.wxwidgets.org/pipermail/wxpython-users/attachments/200711=
19/1500a0d9/attachment.htm


More information about the wxpython-users mailing list