wx.ComboBox and SetValue()

1,247 views
Skip to first unread message

cioma

unread,
Dec 14, 2009, 7:52:24 PM12/14/09
to wxPython-users
Greetings!

I'm using wxPython 2.8.10.1 on Win32 and have the following problem
when using SetValue() on wx.ComboBox (a test example):

I create a combobox:

choices = ['<Browse directory...>', '<Browse list file...>']
source_combobox = wx.ComboBox(parent=self, choices=choices)
source_combobox.Bind(event=wx.EVT_COMBOBOX,
handler=controller.on_evt_combobox)
source_combobox.Bind(event=wx.EVT_TEXT,
handler=controller.on_evt_combobox)

...and bind it to this handler:
class MyController:
def on_evt_combobox(self, event):
event.GetEventObject().SetValue('mytext')
event.GetEventObject().GetValue()

The idea is to change the value of the text field of combobox
depending on combobox item selection.
Now if I press a keyboard button wx.EVT_TEXT event is initiated and
value of the text field becomes 'mytext' (as expected). But if I
select i.e. '<Browse directory...>' from the combobox with a mouse
then textfield value stays as '<Browse directory...>'. But the strange
thing is that GetValue() returns 'mytext' (as expected)

I feel I'm doing something wrong here (refreshment problem?). Could
anyone please give me any ideas?

Mike Driscoll

unread,
Dec 15, 2009, 10:33:07 AM12/15/09
to wxPython-users
Hi,
Try event.GetString() instead.

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

cioma

unread,
Dec 15, 2009, 2:21:03 PM12/15/09
to wxPython-users
The problem is with SetValue(), not with GetValue()

Robin Dunn

unread,
Dec 16, 2009, 3:48:52 PM12/16/09
to wxpytho...@googlegroups.com
Try doing the SetValue after the EVT_COMBOBOX event has completed. My
guess is that the final update of the selection is happening after
control returns to the combobox, so you need to do your change after
that. See wx.CallAfter.


--
Robin Dunn
Software Craftsman
http://wxPython.org

Reply all
Reply to author
Forward
0 new messages