ukulelefant wrote:
I'm trying to horizontally center the text of a wx.StaticText of given
size within a horizontal sizer, e.g. want to have a fixed sized
textbox with the text centered within.
The intuitive solution
class SomeFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1)
panel = wx.Panel(self, -1, size = (400,400))
text = wx.StaticText(panel, -1, "some text", size = (200,
100), style = wx.ALIGN_CENTER)
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(text,1,flag = wx.CENTER)
self.SetSizer(sizer)
doesn't work at all (wx version 2.8.10).
I'm obviously missing something and I'd be glad if someone could point
me into the right direction,
A) send *complete* examples:
http://wiki.wxpython.org/MakingSampleApps
B) the source of you problem is that you are putting the StaticText on a Panel, but setting the sizer on the Frame (self.SetSizer). I try to avoid nesting panels like that in one class:
http://wiki.wxpython.org/wxPython%20Style%20Guide
Addresses this and other issues.
try somethign like (untested):
class SomeFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1)
panel = wx.Panel(self, -1, size = (400,400))
text = wx.StaticText(panel, -1, "some text", size = (200,
100), style = wx.ALIGN_CENTER)
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(text, 1, flag = wx.CENTER)
panel.SetSizer(sizer)
-Chris
···
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker@noaa.gov