I would like to make a frame with 2 buttons on the top ("Button 1" and
"Button 2") and with a white zone below them (the white zone is
resizable with the window). ....
(snip discussion of problem)
A few suggestions... first off, your Zone constructors look like...
class Zone(wxWindow):
def __init__(self, parent, ID_ZONE, pos=wxDefaultPosition,
size=wxDefaultSize):
wxWindow.__init__(self, parent, ID_ZONE, pos, size)
self.SetBackgroundColour(wxNamedColour('white'))
You probably don't want to use your defined ID_ZONE constant here. You want to be
able to create a Zone with any ID, and then pass the desired ID as a parameter to
the constructor. I'd suggest calling this parameter simply id, so that the above
definition becomes:
class Zone(wxWindow):
def __init__(self, parent, id, pos=wxDefaultPosition,
size=wxDefaultSize):
wxWindow.__init__(self, parent, id, pos, size)
self.SetBackgroundColour(wxNamedColour('white'))
Now, when you create a Zone by using Zone(win, ID_ZONE), your desired ID is used
without being (strangely) hardcoded into the Zone class.
Second, and more importantly--there's really no reason for you to be destroying the
zone and then creating a new one. It's much simpler to just change the color of the
one that's already there.
def onButton1(self, event):
self.zonePlace.SetBackgroundColour(wxNamedColour('red'))
(and perhaps a comparable onButton2() that will change it back to white...) It
might be desireable to define a method on your Zone class, that will conveniently
change itself to a given color, though that's not strictly necessary (but could be
useful if you're doing a long series of things involving the current state of a
window, rather than just a simple color change). Also, for this example,
subclassing Zone from wxWindow seems a bit overkill--you could probably use some
sort of wxStatic control and acheive the same thing.
I believe that your layout problem (adding the red square at the wrong size/place)
is due to the fact that you're destroying your original Zone, but not putting the
newZone (which has a new ID, and is a totally different window) into your sizer. So
the sizer knows nothing about it, and can't take care of it for you. This should be
solved by following my second suggestion--just modify the existing window, instead
of replacing it.
Hope this helps....
Jeff Shannon
Technician/Programmer
Credit International
···
On Wed, 31 Oct 2001 15:20:53, Carole Valentin <carole@autosim.no> wrote: