2 questions in wxpython

  1. I have a combobox and a button. When my application starts, a list is added to the combobox. When I press ok button, I need to verify that something is selected in the combobox. If nothing is selected I want to give error message. So how can I verify that.

I tried like this,but it didn’t work

if(self.combo1.GetValue ==True):

    print "%s" % self.combo1.GetValue()

Use GetSelection() – it will return -1 if nothing is selected. You’ll find GetValue() tends to be used in controls like wx.TextCtrl that have a single, set or current ‘value’, and GetSelection() is for controls where they are presented with a choice from which a selection is made. Approximately.

  1. My second question is, I have a frame, In that I have bunch of buttons, textcontrols and combobox and I made all of them to READ ONLY.When I start the application, it will populate some default information in the combobox and textcontrols. So when I click a button called “Edit” it should make them writable. Is that possible? I have attached my code for this piece.

You can call “control.SetStyle(control.GetStyle() ~ wx.TE_READONLY)” to ‘remove’ the read only style… I think. Ahem.

Personally, I’d just use “control.Enable(False)” to make it temporarily ‘read only’, and then later ‘control.Enable(True)’, etc

You can also use the wx.Validator() to ensure that the selection is not
blank. Detailed code in the wPIA book.

Rich

···

On Tue, 4 Dec 2007, Stephen Hansen wrote:

If nothing is selected I want to give error message. So how can I verify
that.

Use GetSelection() -- it will return -1 if nothing is selected. You'll
find GetValue() tends to be used in controls like wx.TextCtrl that have a
single, set or current 'value', and GetSelection() is for controls where
they are presented with a choice from which a selection is made.

--
Richard B. Shepard, Ph.D. | Integrity Credibility
Applied Ecosystem Services, Inc. | Innovation
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863