[wxPython] EVT_BUTTON ??

I am trying to work out how a Button Event works.

I have by default disabled a button as can be seen below:

              AddButton = wxButton(self, aID+10, "Add Record", wxPoint(480,250),size = (275,30))
        AddButton.SetBackgroundColour(wxRED)
        AddButton.SetForegroundColour(wxBLACK)
        EVT_BUTTON(self, aID+10, self.OnClick)

When I click on this button I wish to Enable a button (DeleteButton) that again has been disabled by default, but I get an error message that 'DeleteButton' hasn't been defined.

    def OnClick(self, event):
        DeleteButton.Enable(true)

Where am I going wrong here ??

Pete

Don't you mean self.DeleteButton.Enable(true) ?

···

On Thursday 16 August 2001 08:28, you wrote:

    def OnClick(self, event):
        DeleteButton.Enable(true)

--
Cliff Wells
Software Engineer
Logiplex Corporation
(800) 735-0555

When I click on this button I wish to Enable a button (DeleteButton)
that again has been disabled by default, but I get an error message that
'DeleteButton' hasn't been defined.

    def OnClick(self, event):
        DeleteButton.Enable(true)

Where am I going wrong here ??

That will only work if DeleteButton is global. But what you probably want
to do is save a reference to it in self when you create the button, and then
use self.DeleteButton...

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters?
http://wxPython.org Relax with wxPython!

Hi Cliff,

Tried that as well with no success.

Pete

Cliff Wells wrote:

···

On Thursday 16 August 2001 08:28, you wrote:

   def OnClick(self, event):
       DeleteButton.Enable(true)

Don't you mean self.DeleteButton.Enable(true) ?

try it like this:

class YourClass(wxClass):
    def __init__(self, parent ....):
        self.DeleteButton = wxButton(self, ....)
        self.AddButton = wxButton(self, ....)
         EVT_BUTTON(self, self.AddButton.GetId(), self.OnClick)

def OnClick(self, event):
    self.DeleteButton.Enable(true)

if you don't make the button an attribute of YourClass, then it goes out of
scope at the end of __init__, so Python looks in the global namespace and
can't find a global variable named DeleteButton. By attaching it to
YourClass, you maintain a reference to it (it becomes part of the namespace
of the instance of YourClass)

Regards,
Cliff

···

On Thursday 16 August 2001 18:55, you wrote:

--
Cliff Wells
Software Engineer
Logiplex Corporation
(800) 735-0555

Oops...

please make sure that def OnClick is indented so as to be part of YourClass

Sorry, I was typing and talking on the phone.

···

--
Cliff Wells
Software Engineer
Logiplex Corporation
(800) 735-0555

Hi Cliff,

Yep.... all OK now. what I wasn't doing was putting the self in front of the DeleteButton when I was calling the class.

Thanks again Cliff.

Pete

Cliff Wells wrote:

···

On Thursday 16 August 2001 18:55, you wrote:

try it like this:

class YourClass(wxClass):
   def __init__(self, parent ....):
       self.DeleteButton = wxButton(self, ....)
       self.AddButton = wxButton(self, ....)
        EVT_BUTTON(self, self.AddButton.GetId(), self.OnClick)

def OnClick(self, event):
   self.DeleteButton.Enable(true)

if you don't make the button an attribute of YourClass, then it goes out of scope at the end of __init__, so Python looks in the global namespace and
can't find a global variable named DeleteButton. By attaching it to YourClass, you maintain a reference to it (it becomes part of the namespace of the instance of YourClass)

Regards,
Cliff