How to change the combo box lists as my wish

A

Austin

..................
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?
 
C

Cliff Wells

.................
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?

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
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top