RadioList

Hi Sam,

Thanks for your reply. I must warn you, that I’m a complete beginner…

I have tried this;

class Form1(wxPanel):
def init(self, parent, id):
wxPanel.init(self, parent, id=-1,)

    # Generate
    self.button =wxButton(self, 10, "Generate", wxPoint(200, 300))
    EVT_BUTTON(self, 10, self.OnGenerate)
    
    # Name_Number
    self.radioList = ['1', '2', '3', '4', '5']

rb = wxRadioBox(self, 50, “How many names ?”, wxPoint(20, 250), wxDefaultSize,
self.radioList, 3, wxRA_SPECIFY_COLS)

    EVT_RADIOBOX(self, 50, self.EvtRadioBox)

def OnButton(self, event):        
    Name_Number=int(rb.GetString())

But I get the following error message;

OnGenerate
Name_Number=int(wxRadioBox.GetString())
TypeError: unbound method GetString() must be called with RadioBox instance as first argument (got nothing instead).

Thanks for any help you can offer

Maclolm

In order to access the radiobox object in OnButton,
store (a reference to) it in the panel object.

class Form1(wxPanel):
    def __init__(self, parent, id):
        wxPanel.__init__(self, parent, id=-1,)

        # Generate
        self.button =wxButton(self, 10, "Generate", wxPoint(200, 300))
        EVT_BUTTON(self, 10, self.OnGenerate)

        # Name_Number
        self.radioList = ['1', '2', '3', '4', '5']

        rb = wxRadioBox(self, 50, "How many names ?", wxPoint(20, 250), wxDefaultSize,
                        self.radioList, 3, wxRA_SPECIFY_COLS)

self.rb = ...
^^^^^

        EVT_RADIOBOX(self, 50, self.EvtRadioBox)

    def OnButton(self, event):
        Name_Number=int(rb.GetString())

This should be
def EvtRadioBox(self, event):
    # Get the label and convert it to a number
    Name_Number = int( self.rb.GetString() )
    # ^^^^^
    print 'EvtRadioBox: %r' % Name_Number

BTW, using %r in the print spec will show you
what you *really* have, as opposed to what you
*thought* you had. I find it very helpful.
Also, breaking the Name_Number=... line into
two steps and looking at the intermediate values
could be useful.

- Sam

···

At 2004-09-26 04:13 AM +0100, you wrote:

__________________________________________________________
Spinward Stars, LLC Samuel Reynolds
Software Consulting and Development 303-805-1446
http://SpinwardStars.com/ sam@SpinwardStars.com