Drop Down Box adds an empty element automatically

Hi All:

I have a drop down box on WxGlade where I go add elements and set element as default set selection.

I also see an additional “empty” element added at the very beginning. I do not understand what that would happen… Has anybody observed this?

Thanks!

BTW this on WxGlade 2.8.1.12 and Python 2.7

···

On Sunday, June 9, 2013 3:25:56 PM UTC-7, Kavitha Bhaskaran wrote:

Hi All:

I have a drop down box on WxGlade where I go add elements and set element as default set selection.

I also see an additional “empty” element added at the very beginning. I do not understand what that would happen… Has anybody observed this?

Thanks!

What's the widget? wxChoice? wxCombobox?

Can you provide at least a code snippet?

···

On Sun, Jun 9, 2013 at 6:25 PM, Kavitha Bhaskaran <kukki.kanchana@gmail.com> wrote:

Hi All:

I have a drop down box on WxGlade where I go add elements and set element as
default set selection.

I also see an additional "empty" element added at the very beginning. I do
not understand what that would happen.. Has anybody observed this?

It is a wxChoice and has a list in the “widget” tab and when the GUI launches, the empty element gets added to the top of the list…

···

On Sunday, June 9, 2013 10:45:58 PM UTC-7, Che M wrote:

On Sun, Jun 9, 2013 at 6:25 PM, Kavitha Bhaskaran > > kukki.k...@gmail.com wrote:

Hi All:

I have a drop down box on WxGlade where I go add elements and set element as

default set selection.

I also see an additional “empty” element added at the very beginning. I do

not understand what that would happen… Has anybody observed this?

What’s the widget? wxChoice? wxCombobox?

Can you provide at least a code snippet?

Does that list look like this?:

['', 'one', 'two', 'three']

If not, please provide the relevant code.

···

On Tue, Jun 11, 2013 at 6:08 PM, Kavitha Bhaskaran <kukki.kanchana@gmail.com> wrote:

It is a wxChoice and has a list in the "widget" tab and when the GUI
launches, the empty element gets added to the top of the list..

Hi Che:

No it does not have a space at the beginning.

The code is like self.value_choice = wx.Choice(self.panel1, wx.ID_ANY, choices=[“0”, “1”, “2”, “3”, “4”, “5”, “6”, “7”]). But this adding of null element is only at the beginning and for that to happen, I would have assumed the code to be exactly like your response… but that’s not the case.

But I must tell you, once a value is chosen from the drop down box, after that it seems like the null element has disappeared and then it looks like the way it should “really” be… Just at launch this funny null choice is seen.

Any idea?

···

On Tuesday, June 11, 2013 5:50:17 PM UTC-7, Che M wrote:

On Tue, Jun 11, 2013 at 6:08 PM, Kavitha Bhaskaran > > kukki.k...@gmail.com wrote:

It is a wxChoice and has a list in the “widget” tab and when the GUI

launches, the empty element gets added to the top of the list…

Does that list look like this?:

[‘’, ‘one’, ‘two’, ‘three’]

If not, please provide the relevant code.

The code is like self.value_choice = wx.Choice(self.panel1, wx.ID_ANY,
choices=["0", "1", "2", "3", "4", "5", "6", "7"]). But this adding of null
element is only at the beginning and for that to happen, I would have
assumed the code to be exactly like your response.. but that's not the case.

But I must tell you, once a value is chosen from the drop down box, after
that it seems like the null element has disappeared and then it looks like
the way it should "really" be.. Just at launch this funny null choice is
seen.

Any idea?

If you try the wxPython demo and try out wxChoice on that, does it do
the same thing as what you're describing?

How are you setting the default selection?

On the wxglade version that I am using, on trying to see a “preview” I get some error saying “gray” is not defined. I tried to fix that by saying

#self.plot_hist_listctrl.SetBackgroundColour(wx.SystemSettings_GetColour(gray))
self.plot_hist_listctrl.SetBackgroundColour(‘gray’)

Neither of the 2 lines work!

Or the other thing that happens is, it says “Close Preview” instead of letting me click “Preview”.

I know I have done this before and it has worked for me and I dont know what is going on here.

Widget tab gives me an option for “Selection” and I set it to “0” referring to the 0th element…

Any help would be appreciated…

···

On Tuesday, June 11, 2013 7:28:23 PM UTC-7, Che M wrote:

The code is like self.value_choice = wx.Choice(self.panel1, wx.ID_ANY,

choices=[“0”, “1”, “2”, “3”, “4”, “5”, “6”, “7”]). But this adding of null

element is only at the beginning and for that to happen, I would have

assumed the code to be exactly like your response… but that’s not the case.

But I must tell you, once a value is chosen from the drop down box, after

that it seems like the null element has disappeared and then it looks like

the way it should “really” be… Just at launch this funny null choice is

seen.

Any idea?

If you try the wxPython demo and try out wxChoice on that, does it do

the same thing as what you’re describing?

How are you setting the default selection?

When I have that error previously “Problem previewing gui: global name ‘gray’ not defined”

I had a wxgX.py created in C:\Temp and when I had deleted it, I can preview the panels to see how they look… but now despite deleting the .py files form the Temp folder, I can “Preview”! :frowning:

···

On Tuesday, June 11, 2013 10:50:53 PM UTC-7, Kavitha Bhaskaran wrote:

The code is like self.value_choice = wx.Choice(self.panel1, wx.ID_ANY,

choices=[“0”, “1”, “2”, “3”, “4”, “5”, “6”, “7”]). But this adding of null

element is only at the beginning and for that to happen, I would have

assumed the code to be exactly like your response… but that’s not the case.

But I must tell you, once a value is chosen from the drop down box, after

that it seems like the null element has disappeared and then it looks like

the way it should “really” be… Just at launch this funny null choice is

seen.

Any idea?

If you try the wxPython demo and try out wxChoice on that, does it do

the same thing as what you’re describing?

How are you setting the default selection?

On the wxglade version that I am using, on trying to see a “preview” I get some error saying “gray” is not defined. I tried to fix that by saying

#self.plot_hist_listctrl.SetBackgroundColour(wx.SystemSettings_GetColour(gray))
self.plot_hist_listctrl.SetBackgroundColour(‘gray’)

Neither of the 2 lines work!

Or the other thing that happens is, it says “Close Preview” instead of letting me click “Preview”.

I know I have done this before and it has worked for me and I dont know what is going on here.

Widget tab gives me an option for “Selection” and I set it to “0” referring to the 0th element…

Any help would be appreciated…

On Tuesday, June 11, 2013 7:28:23 PM UTC-7, Che M wrote:

I CANT “preview”. Sorry about the typo above.

···

On Tuesday, June 11, 2013 11:12:21 PM UTC-7, Kavitha Bhaskaran wrote:

When I have that error previously “Problem previewing gui: global name ‘gray’ not defined”

I had a wxgX.py created in C:\Temp and when I had deleted it, I can preview the panels to see how they look… but now despite deleting the .py files form the Temp folder, I can “Preview”! :frowning:

On Tuesday, June 11, 2013 10:50:53 PM UTC-7, Kavitha Bhaskaran wrote:

The code is like self.value_choice = wx.Choice(self.panel1, wx.ID_ANY,

choices=[“0”, “1”, “2”, “3”, “4”, “5”, “6”, “7”]). But this adding of null

element is only at the beginning and for that to happen, I would have

assumed the code to be exactly like your response… but that’s not the case.

But I must tell you, once a value is chosen from the drop down box, after

that it seems like the null element has disappeared and then it looks like

the way it should “really” be… Just at launch this funny null choice is

seen.

Any idea?

If you try the wxPython demo and try out wxChoice on that, does it do

the same thing as what you’re describing?

How are you setting the default selection?

On the wxglade version that I am using, on trying to see a “preview” I get some error saying “gray” is not defined. I tried to fix that by saying

#self.plot_hist_listctrl.SetBackgroundColour(wx.SystemSettings_GetColour(gray))
self.plot_hist_listctrl.SetBackgroundColour(‘gray’)

Neither of the 2 lines work!

Or the other thing that happens is, it says “Close Preview” instead of letting me click “Preview”.

I know I have done this before and it has worked for me and I dont know what is going on here.

Widget tab gives me an option for “Selection” and I set it to “0” referring to the 0th element…

Any help would be appreciated…

On Tuesday, June 11, 2013 7:28:23 PM UTC-7, Che M wrote:

On the wxglade version that I am using, on trying to see a "preview"...

If you have a different question, please start a new thread for that.
This way the subject line is informative to the list, and the archive
of old questions is much more efficient to use and be helpful to the
whole community.

...But to try to answer this new question here this time:

I get some error saying "gray" is not defined. I tried to fix that by saying
#self.plot_hist_listctrl.SetBackgroundColour(wx.SystemSettings_GetColour(gray))

When the Python interpreter gets to the word gray in this line, it
thinks, "gray? What's that? That name has not yet been defined.
That's the error you have. What you meant to do was provide it a
string. That is,

gray

is not the same as

'gray'.

In any case, provided that self.plot_hist_listctrl exists and actually
is a wxListCtrl, this below should work:

        self.plot_hist_listctrl.SetBackgroundColour('gray')

If it does not, either provide the error message you got or explain
what the widget is doing that you expect it should not be doing.

Neither of the 2 lines work!

If you want to use the wxPython list or any mailing list for
programming effectively, instead of writing that something "doesn't
work", provide the error you got or explain what the widget was
supposed to do and then what it actually did instead of that.

Or the other thing that happens is, it says "Close Preview" instead of
letting me click "Preview".

That is a Glade thing, and you'd need to get advice from a Glade user.
Is there a user manual or mailing list?

Widget tab gives me an option for "Selection" and I set it to "0" referring
to the 0th element..

For your original question, just post the code as an attachment to
this list as a small runnable sample (see here:
MakingSampleApps - wxPyWiki).

···

On Wed, Jun 12, 2013 at 1:50 AM, Kavitha Bhaskaran <kukki.kanchana@gmail.com> wrote:

Kavitha Bhaskaran wrote:

No it does not have a space at the beginning.

The code is like self.value_choice = wx.Choice(self.panel1, wx.ID_ANY,
choices=["0", "1", "2", "3", "4", "5", "6", "7"]). But this adding of
null element is only at the beginning and for that to happen, I would
have assumed the code to be exactly like your response.. but that's
not the case.

But I must tell you, once a value is chosen from the drop down box,
after that it seems like the null element has disappeared and then it
looks like the way it should "really" be.. Just at launch this funny
null choice is seen.

This is just the way that control works. Nothing is selected initially,
so it cannot display any of the choices from the list. If you want it
to come up with the first item selected by default, then select it:
    self.value_choice.SetSelection(0)

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

Hi Tim:

I am pretty sure that this was working in the earlier version I was using which is why I was not sure what was going on…

···

On Wednesday, June 12, 2013 9:32:23 AM UTC-7, Tim Roberts wrote:

Kavitha Bhaskaran wrote:

No it does not have a space at the beginning.

The code is like self.value_choice = wx.Choice(self.panel1, wx.ID_ANY,

choices=[“0”, “1”, “2”, “3”, “4”, “5”, “6”, “7”]). But this adding of

null element is only at the beginning and for that to happen, I would

have assumed the code to be exactly like your response… but that’s

not the case.

But I must tell you, once a value is chosen from the drop down box,

after that it seems like the null element has disappeared and then it

looks like the way it should “really” be… Just at launch this funny

null choice is seen.

This is just the way that control works. Nothing is selected initially,

so it cannot display any of the choices from the list. If you want it

to come up with the first item selected by default, then select it:

self.value_choice.SetSelection(0)


Tim Roberts, ti...@probo.com

Providenza & Boekelheide, Inc.

Ya. I had to set the selection manually in the code… at least in this version of wxPython I am using…

···

On Wednesday, June 12, 2013 10:48:57 AM UTC-7, Kavitha Bhaskaran wrote:

Hi Tim:

I am pretty sure that this was working in the earlier version I was using which is why I was not sure what was going on…

On Wednesday, June 12, 2013 9:32:23 AM UTC-7, Tim Roberts wrote:

Kavitha Bhaskaran wrote:

No it does not have a space at the beginning.

The code is like self.value_choice = wx.Choice(self.panel1, wx.ID_ANY,

choices=[“0”, “1”, “2”, “3”, “4”, “5”, “6”, “7”]). But this adding of

null element is only at the beginning and for that to happen, I would

have assumed the code to be exactly like your response… but that’s

not the case.

But I must tell you, once a value is chosen from the drop down box,

after that it seems like the null element has disappeared and then it

looks like the way it should “really” be… Just at launch this funny

null choice is seen.

This is just the way that control works. Nothing is selected initially,

so it cannot display any of the choices from the list. If you want it

to come up with the first item selected by default, then select it:

self.value_choice.SetSelection(0)


Tim Roberts, ti...@probo.com

Providenza & Boekelheide, Inc.