Newbie layout problem.

Hi wxPython-users,

I want to have a layout something like this:

There is a Main Panel with a blank padding in the left and right and a Sub Panel in the middle. In the Sub Panel, there is a Static Text wrapped properly when changing the window size and many other elements are also located in that way. Following is my code snippet but it doesn’t seem to work.

I searched a lot on the Internet, I suppose it has something to do with ‘.AutoLayout()’ and ‘.Layout()’, but I failed to get the expected result after trying for many times. Any suggestions to solve the problem?

Thanks in advance.


import wx

class MyPanel(wx.Panel):

def __init__(self, parent):

super(MyPanel, self).__init__(parent)

self.hsizer = wx.BoxSizer()

self.hsizer.AddStretchSpacer()

self.panel = wx.Panel(self)

self.panel.SetSize((350, -1))

self.vsizer = wx.BoxSizer(wx.VERTICAL)

label = (

"This is a long scentence that I want it wrapped properly, "

"but it doesn't seem to work at all. "

"I prefer if you guys can give any sugeestions or help. "

"For Long Long Long Long Long scentence."

)

style = wx.ALIGN_LEFT

self.static_text = wx.StaticText(self, label=label, style=style)

self.vsizer.Add(self.static_text, flag=wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border=5)

self.static_text.Wrap(self.panel.Size[0])

self.panel.SetSizer(self.vsizer)

self.hsizer.Add(self.panel, flag=wx.ALIGN_CENTER)

self.hsizer.AddStretchSpacer()

self.SetSizer(self.hsizer)

if __name__ == '__main__':

app = wx.App()

frame = wx.Frame(None)

sizer = wx.BoxSizer()

sizer.Add(MyPanel(frame), flag=wx.EXPAND)

frame.SetSizer(sizer)

frame.Show()

app.MainLoop()

Xuan Hu wrote:

···

http://stackoverflow.com/questions/38989282/padding-in-panel-and-static-text-wrap-in-wxpython/39005419#39005419


Robin Dunn

Software Craftsman

http://wxPython.org