problems with changing backgoundcolour in button event function. Also using sizer

I am experimenting with using wxPython
and using sizer in a small experimental sketch. I don’t think

the sizer is my issue (?).

One of the things I do not
understanding is why I can not change the panel background colour

in a button click event handler? I
thought that: panel.SetBackgroundColour(“Blue”) would be
ok.

However, if using this in the button
event function, I get an attribute error:

AttributeError:
‘MyFrame’ object has no attribute ‘panel’

In the MyFrame init code I can and do
assign the panel to a back ground colour , Blue in this case.

In using the button event function I
added this code:

panel.SetBackgroundColour(“Blue”)
gives the error as well as self.panel.SetBackgroundColour(“Blue”).

However in the init section of code I
assign Z=panel. The in the button event function I use:

self.z.SetBackgroundColour(“Red”)
and this changes the background color of the panel.

So I am confused (as usual) on this
behavior.

If someone can help explain what I am
doing wrong that would be a huge help!

AttributeError: 'MyFrame' object has no attribute 'panel'

I'd have to see your code or a small runnable sample to exactly know what
the issue is, but it's important to realize that when Python says that
MyFrame has no attribute named "panel", it is not kidding--you should
believe it. So, then, where did you fail to write (something like) this
line?:

self.panel = wx.Panel(self)

···

On Sun, Mar 23, 2014 at 5:04 PM, EightBits <jlala2010@gmail.com> wrote:

The Event Handler gets the event, which can access the EventObject.

Once you get the EventObject, you can get the Parent.

Or just declare self.panel somewhere in the code that makes this work. It depends on where your Event Handler is in the code (Frame level, or Panel level, or elsewhere)

Josh

···

On Sunday, March 23, 2014 2:04:54 PM UTC-7, EightBits wrote:

I am experimenting with using wxPython
and using sizer in a small experimental sketch. I don’t think

the sizer is my issue (?).

Thanks for the reply, I will keep banging away.

···

--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/problems-with-changing-backgoundcolour-in-button-event-function-Also-using-sizer-tp5720548p5720557.html
Sent from the wxPython-users mailing list archive at Nabble.com.