Using the combo box

Questions on using Python (2.7.3) and WxPython comboBox.

I have a script where the cbo gets items (strings) added using the .Append
method.
Once the cbo is populated (max 10 items) I then select one of the items in
the cbo drop down.
This places the selection at the top of the cbo display and the drop down
section 'closes up' with
only the selected displayed in the cbo text section.

I have a button/function that clears the cbo, but the selected version
remains in the display (?)
The remaining items that were added are gone, but the selected item remains
displayed in the cbo
I tried self.cbo.Clear() , that does clear out the cbo, but the selected
text remains in the display.
The next time I add items to the cbo, the previous selected item is not
there even though it was
in the cbo text display.

So, two questions, How can I clear out all of the text in the cbo including
the selected item ?
       And is there a approach to have the comboBox to expand(drop down) and
show the compleat list ?

Also using WxPython /usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/

Hope I have supplied the information needed to get an answer.
Thank You.

···

--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/Using-the-combo-box-tp5722906.html
Sent from the wxPython-users mailing list archive at Nabble.com.

Questions on using Python (2.7.3) and WxPython comboBox.

I have a script where the cbo gets items (strings) added using the .Append

method.

Once the cbo is populated (max 10 items) I then select one of the items in

the cbo drop down.

This places the selection at the top of the cbo display and the drop down

section ‘closes up’ with

only the selected displayed in the cbo text section.

I have a button/function that clears the cbo, but the selected version

remains in the display (?)

The remaining items that were added are gone, but the selected item remains

displayed in the cbo

I tried self.cbo.Clear() , that does clear out the cbo, but the selected

text remains in the display.

The next time I add items to the cbo, the previous selected item is not

there even though it was

in the cbo text display.

So, two questions, How can I clear out all of the text in the cbo including

the selected item ?

I believe you will need to do what you were doing, but also add a call to SetSelection(-1)

And is there a approach to have the comboBox to expand(drop down) and

show the compleat list ?

Not sure what you mean, this is the default behavior of any ComboBox from what I can tell. Whether the complete list is displayed depends on if there is enough screen space available.

···

On Friday, October 31, 2014 3:20:02 PM UTC-7, EightBits wrote:

Thanks Nathan for he suggestion. I added self.cbo.SetSelection(-1) but it did
not delete the text
item displayed. Perhaps I should try a multiline textbox ? I am thinking
that this should work
using the combo box.
It is not that big of a deal, this is just a personal snippet I am using to
generate a list (10 items) of random passwords and then select one of them
to use and that selection is saved in a file for later use.
I just wanted to figure it out ( a hobbyist) and see if I can make things
work. Once again, thanks
for your suggestion.

···

--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/Using-the-combo-box-tp5722906p5722908.html
Sent from the wxPython-users mailing list archive at Nabble.com.

Hello,

Try:

cboControl.SetValue("")

Saludos / Best regards

Mario Lacunza
Email:: mlacunza@gmail.com
Personal Website:: http://www.lacunza.biz/
Hosting:: http://mlv-host.com/
Mascotas Perdidas:: http://mascotas-perdidas.com/
Google Hangouts / / Skype: mlacunzav

···

El 31/10/14 a las 17:19, eightbits escribió:

Questions on using Python (2.7.3) and WxPython comboBox.

I have a script where the cbo gets items (strings) added using the .Append
method.
Once the cbo is populated (max 10 items) I then select one of the items in
the cbo drop down.
This places the selection at the top of the cbo display and the drop down
section 'closes up' with
only the selected displayed in the cbo text section.

I have a button/function that clears the cbo, but the selected version
remains in the display (?)
The remaining items that were added are gone, but the selected item remains
displayed in the cbo
I tried self.cbo.Clear() , that does clear out the cbo, but the selected
text remains in the display.
The next time I add items to the cbo, the previous selected item is not
there even though it was
in the cbo text display.

So, two questions, How can I clear out all of the text in the cbo including
the selected item ?
        And is there a approach to have the comboBox to expand(drop down) and
show the compleat list ?

Also using WxPython /usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/

Hope I have supplied the information needed to get an answer.
Thank You.

--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/Using-the-combo-box-tp5722906.html
Sent from the wxPython-users mailing list archive at Nabble.com.

Thanks Mario. I did try that, that was the first thing I did. I have been
searching the internet and one
of the things I have yet to try is the way I am creating the cbo.
self.PWcbo = wx.ComboBox(panel,-1,size=(200,26))
I think there are additional parameters that may be effecting how this
object works. I will keep searching
and will post if and when I get to the bottom of this.

BTW: How does one add code in a post here? I saw an example but not sure
where/how to do that(?).
        OOPS, I see there is a more->file upload.

Best Regards

···

--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/Using-the-combo-box-tp5722906p5722911.html
Sent from the wxPython-users mailing list archive at Nabble.com.

I’ve not done this myself, but the documentation has this: wxPython API Documentation — wxPython Phoenix 4.2.2 documentation

I would try GetValue to get the string in that textbox, and uses it’s length in a call to Replace:

cbo.Replace(0, length, “”)

See how that goes. Shouldn’t be that difficult of abstruse, however. Can you actually retrieve the value left displayed by a call to GetValue?

···

On Friday, October 31, 2014 3:20:02 PM UTC-7, EightBits wrote:

Questions on using Python (2.7.3) and WxPython comboBox.

I have a script where the cbo gets items (strings) added using the .Append

method.

Once the cbo is populated (max 10 items) I then select one of the items in

the cbo drop down.

This places the selection at the top of the cbo display and the drop down

section ‘closes up’ with

only the selected displayed in the cbo text section.

I have a button/function that clears the cbo, but the selected version

remains in the display (?)

The remaining items that were added are gone, but the selected item remains

displayed in the cbo

I tried self.cbo.Clear() , that does clear out the cbo, but the selected

text remains in the display.

The next time I add items to the cbo, the previous selected item is not

there even though it was

in the cbo text display.

So, two questions, How can I clear out all of the text in the cbo including

the selected item ?

   And is there a approach to have the comboBox to expand(drop down) and

show the compleat list ?

Also using WxPython /usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/

Hope I have supplied the information needed to get an answer.

Thank You.

View this message in context: http://wxpython-users.1045709.n5.nabble.com/Using-the-combo-box-tp5722906.html

Sent from the wxPython-users mailing list archive at Nabble.com.

chajadan: Sounds like a approach. I will test that out and report later.
Probably tomorrow.
I am not clear on how to get use the GetValue because the text control is
embedded in the cbo.
Because the code already knows the length, the call to generate the strings
inside the cbo are specified
that should allow me to test it that way.
Thanks for the suggestion.
Best Regards.

···

--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/Using-the-combo-box-tp5722906p5722913.html
Sent from the wxPython-users mailing list archive at Nabble.com.

chajadan: OK, I didn't wait, tried the cbo.Replace method and it worked like
a champ!
All I have to do now is figure out how to get the 'length' in to that call.
Once I have verified that it is working, then I will post a resolved
message.
Great approach, I can see I have a long way to go.

···

--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/Using-the-combo-box-tp5722906p5722914.html
Sent from the wxPython-users mailing list archive at Nabble.com.

You just call len(cbo.GetValue()) on len(self.cbo.GetValue()).

The thing is, I would suspect cbo.SetValue(“”) would work for you, as someone else already suggested, and the fact you’re unsure how to call GetValue makes me wonder if your previous attempt at SetValue was not valid. Using replace as I suggested is for sure a hacky roundabout way to do this, but I’m glad you have at least one concrete lead.

···

On Saturday, November 1, 2014 5:56:32 PM UTC-7, EightBits wrote:

chajadan: OK, I didn’t wait, tried the cbo.Replace method and it worked like

a champ!

All I have to do now is figure out how to get the ‘length’ in to that call.

Once I have verified that it is working, then I will post a resolved

message.

Great approach, I can see I have a long way to go.

View this message in context: http://wxpython-users.1045709.n5.nabble.com/Using-the-combo-box-tp5722906p5722914.html

Sent from the wxPython-users mailing list archive at Nabble.com.

chajadan: Well, I went back and was able to use the GetValue() method and the
SetValue("") and it did work.

Is there also a method to enable the drop down text control when it is
populated with selections?
I did add a Setfocus, but that only highlights the text control. What I
would like to accomplish is
to display the Combobox text contents once it is populated.

Best Regards.

···

--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/Using-the-combo-box-tp5722906p5722973.html
Sent from the wxPython-users mailing list archive at Nabble.com.

I don’t see a method for dropping the list open, but there are different kinds of comboboxes:

wx.CB_SIMPLE
Creates a combobox with a permanently displayed list. Windows only.
wx.CB_DROPDOWN
Creates a combobox with a drop-down list.
One of those always shows the list, and the other, I presume, is the kind that let’s the user show and hide it. So what you could do is create two controls, one of each type, and then dynamically expose the one you want, making sure to update their lists/entries so they match.

···

On Wednesday, November 5, 2014 2:51:58 PM UTC-8, EightBits wrote:

chajadan: Well, I went back and was able to use the GetValue() method and the

SetValue(“”) and it did work.

Is there also a method to enable the drop down text control when it is

populated with selections?

I did add a Setfocus, but that only highlights the text control. What I

would like to accomplish is

to display the Combobox text contents once it is populated.

Best Regards.

View this message in context: http://wxpython-users.1045709.n5.nabble.com/Using-the-combo-box-tp5722906p5722973.html

Sent from the wxPython-users mailing list archive at Nabble.com.

/Eightbits/,

It looks like you should be using the ComboCtrl <http://wxpython.org/Phoenix/docs/html/ComboCtrl.html&gt; rather than the ComboBox control. You have to do a little more work to create it, /see the example/ <http://wxpython.org/Phoenix/docs/html/ComboCtrl.html\#phoenix\-title\-setting\-custom\-popup\-for\-comboctrl&gt;, but it has exactly the method that you are looking for - Popup <http://wxpython.org/Phoenix/docs/html/ComboCtrl.html\#ComboCtrl\.Popup&gt; which will show the drop-down on demand.

Gadget/Steve

···

On 05/11/14 22:51, eightbits wrote:

chajadan: Well, I went back and was able to use the GetValue() method and the
SetValue("") and it did work.

Is there also a method to enable the drop down text control when it is
populated with selections?
I did add a Setfocus, but that only highlights the text control. What I
would like to accomplish is
to display the Combobox text contents once it is populated.

Best Regards.

--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/Using-the-combo-box-tp5722906p5722973.html
Sent from the wxPython-users mailing list archive at Nabble.com.


Eightbits,

It looks like you should be using the [ComboCtrl](http://wxpython.org/Phoenix/docs/html/ComboCtrl.html)
rather than the ComboBox control.  You have to do a little more work

to create it, * see
the example*
, but it has exactly the method that you are
looking for - Popup
which will show the drop-down on demand.

It seems ComboBox has the Popup method:
http://wxpython.org/Phoenix/docs/html/ComboBox.html#ComboBox.Popup

···

On Wednesday, November 5, 2014 10:18:58 PM UTC-8, Gadget Steve wrote:

Gadget/Steve

Nathan: I did try the Popup method, it did not change anything. I read in the
WxPython book in the section using the combobox and it's association with
the ListCntrl and it does state that the ListBox control
behavior displays the text contents only after the drop down arrow is
clocked.
So, for the time I will accept that. This is just a personal snippet and I
am the only one that will use it.
Thanks to all for the helpful information and suggestions,

Best Regards.

···

--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/Using-the-combo-box-tp5722906p5722988.html
Sent from the wxPython-users mailing list archive at Nabble.com.

You could try combo.SetSelection(0) then combo.ChangeValue(combo.GetTextSelection())

···

On Thursday, November 6, 2014 12:57:49 PM UTC-8, EightBits wrote:

Nathan: I did try the Popup method, it did not change anything. I read in the

WxPython book in the section using the combobox and it’s association with

the ListCntrl and it does state that the ListBox control
behavior displays the text contents only after the drop down arrow is

clocked.

OK Nathan. That is something I have not attempted before. I will give that
shop and then post here when
I get something to post.

···

--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/Using-the-combo-box-tp5722906p5722991.html
Sent from the wxPython-users mailing list archive at Nabble.com.

combo.SetSelection(0) then combo.ChangeValue(combo.GetTextSelection())

gives the error: AttributeError: 'ComboBox' object has no attribute
'ChangeValue'

and of course the proper name for the combo was "self.PWcbo"

But, I am OK with the way this code works now.

···

--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/Using-the-combo-box-tp5722906p5722994.html
Sent from the wxPython-users mailing list archive at Nabble.com.

Umm, I am not sure why that is… On my GUI with a read-only ComboBox I get this error:
return core.TextEntryBase_ChangeValue(*args, **kwargs)

PyAssertionError: C++ assertion “!HasFlag(wxCB_READONLY)” failed at …..\src\msw\combobox.cpp(421) in wxComboBox::GetEditHWND(): read-only combobox doesn’t have any edit control

but in the ComboBox.py demo file (which doesn’t instantiate the widget as read-only), using ChangeValue works just fine, see attached pic.

···

On Friday, November 7, 2014 12:09:47 PM UTC-8, EightBits wrote:

combo.SetSelection(0) then combo.ChangeValue(combo.GetTextSelection())

gives the error: AttributeError: ‘ComboBox’ object has no attribute

‘ChangeValue’