entries between labels dynamically

Jeff Shannon jeff at ccvcorp.com
Fri Feb 15 15:51:31 EST 2002


Artur Skura wrote:

> In other words: I have to put text entries between text labels.
> Now can you suggest an easy, lazy way of doing this (with any
> toolkit) so things don't pile up and everything looks nice?

Using wxPython, you can set the text of a wxStaticText control to be
whatever you want:

    MyLabel = wxStaticText(parent, wxNewId(), "Starting Text")

    ....

    MyLabel.SetLabel("New, expanded text!")

wxPython also has sizers, which will automatically resize windows and
controls, so that you can change your text, have the sizer recalculate
the layout, and refresh your dialog.  (It can take a bit of fiddling to
get sizers to work the way you want, but once you get the hang of them,
they're *very* helpful!)  If you want to insert specific text into a
'template' sentence, then that's easy to do using Python's string
interpolation:

   MyLabel.SetLabel("Now serving %s!" % mydata)

And of course, you can dynamically add and remove controls from dialogs
and sizers, so you can easily change your dialog on the fly.

Jeff Shannon
Technician/Programmer
Credit International





More information about the Python-list mailing list