2014-11-04 64 views
0

我想在图像后放置一个StaticLine(垂直)。静态线后,我有一些按钮。我已将它们全部放入BoxSizer(水平)中。但是在运行时我看不到静态线。 我在这里做错了什么?请帮帮我。在BoxSizer中的图像后的WxPython StaticLine

谢谢。

这是一些代码。

class Frame1(wx.Frame): 
    def __init__(self, *args, **kwds): 
     wx.Frame.__init__(self, *args, **kwds) 
     self.panel1 = wx.Panel(self, wx.ID_ANY) 
     img = wx.EmptyImage(MaxImageSize, MaxImageSize) 
     self.imgctrl = wx.StaticBitmap(self.panel1, wx.ID_ANY, wx.BitmapFromImage(img)) 
     self.st = wx.StaticLine(self.panel1, wx.ID_ANY, style=wx.LI_VERTICAL) 
     self.but = wx.Button(self.panel1, wx.ID_ANY, 'OK') 
     self.hbox = wx.BoxSizer(wx.HORIZONTAL) 
     self.hbox.Add(self.imgctrl, 0, wx.ALL, 5) 
     self.hbox.Add(self.st, 0, wx.ALL, 5) 
     self.hbox.Add(self.but, 1, wx.ALL, 5) 
     self.panel1.SetSizer(self.hbox) 
     self.hbox.Fit(self.panel1) 

回答

1

当您将静态行添加到sizer中时,需要设置扩展标志,以便扩展以垂直填充sizer。

import wx 

class Frame1(wx.Frame): 
    def __init__(self, *args, **kwds): 
     wx.Frame.__init__(self, *args, **kwds) 
     self.panel1 = wx.Panel(self, wx.ID_ANY) 
     img = wx.EmptyImage(100, 100) 
     self.imgctrl = wx.StaticBitmap(self.panel1, wx.ID_ANY, wx.BitmapFromImage(img)) 
     self.st = wx.StaticLine(self.panel1, wx.ID_ANY, style=wx.LI_VERTICAL) 
     self.but = wx.Button(self.panel1, wx.ID_ANY, 'OK') 
     self.hbox = wx.BoxSizer(wx.HORIZONTAL) 
     self.hbox.Add(self.imgctrl, 0, wx.ALL, 5) 
     self.hbox.Add(self.st, 0, wx.ALL | wx.EXPAND, 5) 
     self.hbox.Add(self.but, 1, wx.ALL, 5) 
     self.panel1.SetSizer(self.hbox) 
     self.hbox.Fit(self.panel1) 

if __name__ == '__main__': 
    app = wx.App(False) 
    frame_1 = Frame1(None) 
    frame_1.Show() 
    app.MainLoop() 
+0

谢谢。这解决了问题。 – Joydeep 2014-11-04 17:07:28