[wxPython-users] Removing widgets
Christopher Barker
Chris.Barker at noaa.gov
Mon Aug 7 10:20:30 PDT 2006
Adam Spencer wrote:
> I have been struggling with this for a while now. I have created a simple=
GUI, =
> this is what I am trying to achieve.
A few comments:
1) Thanks for posting a complete runnable sample -- that's the best way =
to get help here. However, next time send it as an enclosure, rather =
than inline in the email -- emails clients have a way of messing up =
whitespace, etc.
2) one of you IDs was specified as -2, which isn't valid -- weird. =
However, that's why I like to use: wx.ID_ANY rather than -1. Or better =
yet, use keyword arguments, and you can leave off the ID parameter =
altogether:
wx.Button(self, label=3D"Buttons 1")
A few more comments as I go through the code:
frame =3D ID.GetEventObject().GetGrandParent()
This is fragile: what if you re-factor the code and put another panel =
between here and the frame? You can use wx.GetTopLevelParent(self), or, =
better yet, keep track of your frame and/or data in a different way.
In: Buttons1, you've got:
typesizer and self.typesizer -- I think there is some confusion here.
Buttons1 is used as a handler - it will get called with an event as a =
parameter, not an ID. You seem to be using it correctly, but calling it =
"ID" is pretty confusing
The key issue:
You can hide and show stuff in a sizer by putting all the objects you =
want in it, then hide() the ones you don't' want. So I'd create the =
buttons first, then just call show() and Hide as you need in the =
handlers. You can add all the button to self.typesizer in __init__, then =
show them later.
I've enclosed a working version
I also took the liberty of cleaning up some style issues, and using a =
loop to create the buttons -- I subscribe heartily to the DRY (don't =
Repeat Yourself) principle. If you find yourself writing a bunch of =
lines of code that are almost identical -- you can probably automate it =
somehow.
If this were me, I'd probably put the buttons on a wx.Panel, you'd hove =
one panel for each set of three button, then you could just Show() and =
Hide() that panel.
-Chris
-- =
Christopher Barker, Ph.D.
Oceanographer
=
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
-------------- next part --------------
A non-text attachment was scrubbed...
Name: junk.py
Type: text/x-python
Size: 2673 bytes
Desc: not available
Url : http://lists.wxwidgets.org/pipermail/wxpython-users/attachments/20060=
807/ab771bbe/junk.py
More information about the wxpython-users
mailing list