Feed wxComboBox with dictionary/hash

R

Roland Rickborn

Hi folks,

I am relatively new to Python. Although I read a lot of howtos,
introductions and wikis, I am still having trouble ;-)

My querstion:
As the subject says, I'd like to feed a wx.ComboBox with a
dictionary/hash. According to the posting of Stano Paska ("wxComboBox
You must use something like
combo.Append('aaa', 'a')
combo.Append('bbb', 'b')
...

My problem is:
my data has thousands of entries. Therefore, I'd like to feed the
combobox with a dictionary (which itself is fed by a database query).

My first question:
how can a wx.ComboBox be fed by a dictionary?

For further help, Stano says:
read manual for more details...

Ok, I'd like to. But which one?
I was reading http://www.wxpython.org/docs/api/wx.ComboBox-class.html
and didn't even find the above mentioned append method :-(

TIA,
Roland R.
 
I

Iain King

Roland said:
Hi folks,

I am relatively new to Python. Although I read a lot of howtos,
introductions and wikis, I am still having trouble ;-)

My querstion:
As the subject says, I'd like to feed a wx.ComboBox with a
dictionary/hash. According to the posting of Stano Paska ("wxComboBox


My problem is:
my data has thousands of entries. Therefore, I'd like to feed the
combobox with a dictionary (which itself is fed by a database query).

My first question:
how can a wx.ComboBox be fed by a dictionary?

For further help, Stano says:


Ok, I'd like to. But which one?
I was reading http://www.wxpython.org/docs/api/wx.ComboBox-class.html
and didn't even find the above mentioned append method :-(

TIA,
Roland R.

wxComboBox inherits from wxControlWithItems (as does wx.ListBox, and
other controls which hold lists). See:
http://wxwidgets.org/manuals/2.6.3/wx_wxcontrolwithitems.html#wxcontrolwithitems

Iain
 
S

Simon Forman

Roland said:
Hi folks, ....
As the subject says, I'd like to feed a wx.ComboBox with a
dictionary/hash. According to the posting of Stano Paska ("wxComboBox


My problem is:
my data has thousands of entries. Therefore, I'd like to feed the
combobox with a dictionary (which itself is fed by a database query).

My first question:
how can a wx.ComboBox be fed by a dictionary?
....
TIA,
Roland R.

I don't know if this is the best way to do this, but you could just
feed the wx.ComboBox from the dict in a loop like this:

for k, v in data_dict.iteritems(): combo.Append(k, v)

From the manual link that Iain King posted
(http://wxwidgets.org/manuals/2.6.3/wx_wxcontrolwithitems.html#wxcontrolwithitems)
it appears that you might be able to pass a list of strings to the
Append() method. However, it also appears that you wouldn't be able to
associate any "clientData" with the strings.

Peace,
~Simon
 
P

Peter Decker

My first question:
how can a wx.ComboBox be fed by a dictionary?

This is one of those annoying things about wxPython that made me so
happy to switch to using the dabo.ui wrapper for wxPython instead. You
can set up the dabo.ui.dComboBox like this, given a dictionary 'dd':

cb = dabo.ui.dComboBox(self)
cb.Choices = dd.Values()
cb.Keys = dd

You can then get the selected item via the StringValue property, or
its associated key via the KeyValue property. That's it. Simple.
 

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
474,294
Messages
2,571,511
Members
48,206
Latest member
EpifaniaMc

Latest Threads

Top