How to change the combo box lists as my wish

Discussion in 'Python' started by Austin, Nov 1, 2004.

  1. Austin

    Austin Guest

    ..................
    self.diskList = ['3','4','5']
    self.cB = wxComboBox(self,-1,wxDefaultPosition,wxDefaultSize,self.diskList)
    ..................

    The code is executed initially.
    If i want to update only the diskList, what could i do?
     
    Austin, Nov 1, 2004
    #1
    1. Advertisements

  2. Austin

    Cliff Wells Guest

    I take it you want the list and the wxComboBox tied together so that
    updating the python list automatically updates the wxComboBox. There is
    no built-in way to do this. However, you could do something like this:

    import wx

    class CBList(list):
    def __init__(self, combobox):
    list.__init__(self)
    self.combobox = combobox

    def __setitem__(self, key, value):
    list.__setitem__(self, key, value)
    self.combobox.SetString(key, value)

    def __delitem__(self, key):
    list.__delitem__(self, key)
    self.combobox.Delete(key)

    def append(self, value):
    list.append(self, value)
    self.combobox.Append(value)


    class MyFrame(wx.Frame):
    def __init__(self, parent, id, title):
    wx.Frame.__init__(self, parent, id, title)
    cb = wx.ComboBox(self, -1)
    choices = CBList(cb)

    choices.append('test 1')
    choices.append('test 2')
    choices[0] = 'replace test 1'
    del choices[1]

    if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = MyFrame(None, -1, 'test')
    frame.Show(True)
    app.MainLoop ()


    Regards,
    Cliff
     
    Cliff Wells, Nov 2, 2004
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.