【问题标题】:WxPython StaticLine after Image in BoxSizerBoxSizer 中图像后的 WxPython StaticLine
【发布时间】:2014-12-31 06:51:40
【问题描述】:

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

谢谢。

这是一些代码。

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)

【问题讨论】:

    标签: image wxpython boxsizer


    【解决方案1】:

    当您将静态线添加到 sizer 时,您需要设置 expand 标志,因此它会扩展以垂直填充 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()
    

    【讨论】:

      猜你喜欢
      • 2018-10-01
      • 1970-01-01
      • 2013-07-28
      • 1970-01-01
      • 2020-09-07
      • 1970-01-01
      • 2021-06-14
      • 2019-10-17
      • 1970-01-01
      相关资源
      最近更新 更多