since some months I use wxPython and I like it alot. Unfortunately there are
some little problems that confuse me and one of them is the problem of
automatically wrapping static text.
I want a Panel (page in a notebook for that matter) which contains a StaticText
which can be several lines long.
The frame and the text within shall be resizable. The text shall take all
available space but not more.
A long StaticText *without a Wrap* goes way out of its surrounding frame.
A StaticText with a call to Wrap wraps nicely but ist width is fixed by
the call to wrap.
If I enlarge the frame-width the width of the StaticText remains the
same. If I reduce the width below the original Wrap Parameter the Text wraps
again but the end is invisible, it should show a scrollbar in this case.
Consider the folowing example and comment the Wrap statement in and out.
* Watch out that the content of the text1 should be on one or two lines
to show the problem. GMANE forces me to break the lines.
Watch also for the effect of using wx.EXPAND or not in the 'sizer.Add'.
We have 4 different ways to sho this text - but none of them good from my POV.
Thanks for listening
def __init__(self, *args,**kwargs):
pan = wx.Panel(self)
text1 = wx.StaticText(pan, -1, """
his release is mostly about fixing a number of bugs and inconsistencies in
wxWidgets and wxPython. In other words, there have been a whole lot more
changes than what is listed here, but they are not new features or API visible
changes, which is what are usually listed in this file. Some Menu APIs
make things more consistent. Added wx.MenuBar.SetMenuLabel,
wx.MenuBar.GetMenuLabel, wx.MenuBar.GetMenuLabelText, wx.Menu.GetLabelText,
wx.MenuItem.GetItemLabelText, wx.MenuItem.GetLabelText. The Get...Label
functions get the raw label with mnemonics and accelerators, and the
Get...LabelText functions get the text only, without mnemonics/accelerators.
Added wx.BORDER_THEME style. Thi
text1.Wrap(400) ### Comment in and out and resize the frame
sizer = wx.BoxSizer(wx.HORIZONTAL) ###Try this and the next one
# sizer.Add(text1,wx.EXPAND) ###Try this and the previous one
> Hello list,
> since some months I use wxPython and I like it alot. Unfortunately there are
> some little problems that confuse me and one of them is the problem of
> automatically wrapping static text.
> I want a Panel (page in a notebook for that matter) which contains a StaticText
> which can be several lines long.
> The frame and the text within shall be resizable. The text shall take all
> available space but not more.
> A long StaticText *without a Wrap* goes way out of its surrounding frame.
> A StaticText with a call to Wrap wraps nicely but ist width is fixed by
> the call to wrap.
> If I enlarge the frame-width the width of the StaticText remains the
> same. If I reduce the width below the original Wrap Parameter the Text wraps
> again but the end is invisible, it should show a scrollbar in this case.
Perhaps the attached would be a good starting point for you.
http://wxPython.org Java give you jitters? Relax with wxPython!
def __init__(self, parent, id=-1, label="",
wx.PyControl.__init__(self, parent, id, pos, size, wx.NO_BORDER,
self.st = wx.StaticText(self, -1, label, style=style)
self._label = label # save the unwrapped text
# this should return something meaningful for what the best
# size of the widget is, but what that size should be while we
# still don't know the actual width is still an open
# question... Just return a dummy value for now.
text = """\
A certain king had a beautiful garden, and in the garden stood a tree which bore golden apples. These apples were always counted, and about the time when they began to grow ripe it was found that every night one of them was gone. The king became very angry at this, and ordered the gardener to keep watch all night under the tree. The gardener set his eldest son to watch; but about twelve o'clock he fell asleep, and in the morning another of the apples was missing. Then the second son was ordered to watch; and at midnight he too fell asleep, and in the morning another apple was gone. Then the third son offered to keep watch; but the gardener at first would not let him, for fear some harm should come to him: however, at last he consented, and the young man laid himself under the tree to watch. As the clock struck twelve he heard a rustling noise in the air, and a bird came flying that was of pure gold; and as it was snapping at one of the apples with its beak, the gardener's son jumped up and shot an arrow at it. But the arrow did the bird no harm; only it dropped a golden feather from its tail, and then flew away. The golden feather was brought to the king in the morning, and all the council was called together. Everyone agreed that it was worth more than all the wealth of the kingdom: but the king said, 'One feather is of no use to me, I must have the whole bird.'
def __init__(self, *args, **kw):
wx.Frame.__init__(self, *args, **kw)
p = wx.Panel(self)
box = wx.StaticBox(p, -1, "AutoWrapStaticText")
sbs = wx.StaticBoxSizer(box, wx.VERTICAL)
awst = AutoWrapStaticText(p, label=text)
sbs.Add(awst, 1, wx.EXPAND)