我想将{strong>垂直和水平元素与wx.BoxSizer
居中。我尝试了这个不成功(结果:元素垂直居中但不是水平居中......):
vsizer = wx.BoxSizer(wx.VERTICAL)
hsizer = wx.BoxSizer(wx.HORIZONTAL)
vsizer.AddStretchSpacer(1)
vsizer.Add(hsizer, 0, wx.ALL, 15)
vsizer.AddStretchSpacer(1)
self.SetSizer(vsizer)
hsizer.AddStretchSpacer(1)
hsizer.Add(wx.StaticBitmap(self, -1, myimg), 0, wx.ALL, 15)
hsizer.AddStretchSpacer(1)
如何使用wx.BoxSizer
垂直和水平居中元素?
答案 0 :(得分:2)
这是一个简单的例子:
import wx
class Frame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "Vertical center")
self.text = wx.StaticText(self, label=("This should be centered both"
" vertically and horizontally"))
sizer_v = wx.BoxSizer(wx.VERTICAL)
sizer_h = wx.BoxSizer(wx.HORIZONTAL)
sizer_h.Add(self.text, 1, wx.CENTER)
sizer_v.Add(sizer_h, 1, wx.CENTER)
self.SetSizer(sizer_v)
self.Show()
app = wx.App()
Frame()
app.MainLoop()
wx.CENTER
将wx.BoxSizer
内的元素居中(滚动到页面底部):http://wiki.wxpython.org/BoxSizerTutorial
HTH