Using Mike Driscoll's code as a baseline, I hope this demonstrates my problem. There are two different versions of using "txt". Here are three things I want you to try:
Run it as is. With my StaticWrapText. At first it does not display correctly, but it resized the window, and it works EXACTLY as I want. The empty / empty space below the text in front of the "button"
Change these two lines (change the comments):
txt = wx.StaticText (panel, label = text)
#txt = StaticWrapText (panel, label = text)
Now you will see that there is no wrapper, and the text is always on only one line. Definitely not what we want. This is due to "sizer.Add (txt, 0, wx.EXPAND, 5)" ... so we move on to Part 3 ...
Save the changes from Part 2, and also change:
sizer.Add (txt, 0, wx.EXPAND, 5)
in:
sizer.Add (txt, 1, wx.EXPAND, 5)
So now the static text will expand. This is CLOSED to work ... BUT I do not want all this empty space between the text and the button. If you make the window large, there will be a lot of lost space. See Part 1 after resizing a window to see the difference.
the code:
import wx class StaticWrapText(wx.PyControl): def __init__(self, parent, id=wx.ID_ANY, label='', pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.NO_BORDER, validator=wx.DefaultValidator, name='StaticWrapText'): wx.PyControl.__init__(self, parent, id, pos, size, style, validator, name) self.statictext = wx.StaticText(self, wx.ID_ANY, label, style=style) self.wraplabel = label
EDIT:
AHHH ... finally! I tried using the Layout () method at almost every level of the program, but I really needed to use Layout () on SIZER, which was found using the GetSizer () method, or you can send SendSizeEvent () to the panel (commented in the code below). So the following is now EXACTLY what I want! Thanks for the help. The only other change was to save the panel with self.panel in the frame class. As a note, I had to put this statement AFTER the .Show () frame or it did not work correctly.
the code:
import wx class StaticWrapText(wx.PyControl): def __init__(self, parent, id=wx.ID_ANY, label='', pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.NO_BORDER, validator=wx.DefaultValidator, name='StaticWrapText'): wx.PyControl.__init__(self, parent, id, pos, size, style, validator, name) self.statictext = wx.StaticText(self, wx.ID_ANY, label, style=style) self.wraplabel = label
As a final note in my source program, the next line should be added immediately before or after the frame. Show ():
frame.panel.Panel2.GetSizer (). Layout ()
Interesting ... with this original example, it may be before or after frame.Show (), but another example requires it to be after frame.Show (). I donβt know why, but just put it and you are safe.