wxpython:防止特定字段的水平增长

时间:2011-04-13 13:14:43

标签: wxpython

我有一个有三个基本区域的gui。一个列表控件,它跨越窗口的整个宽度,位于按钮按钮功能分组的两个按钮区域之上。

调整窗口大小时,所有3个区域的大小都与窗口的增长成比例。我想要发生的是两个按钮区域,不做任何高度增长,但允许宽度增长。

这可能吗?

这是我正在使用的例子。我使用wxGlade

生成了这个
#!/usr/bin/env python
# -*- coding: iso-8859-15 -*-
# generated by wxGlade 0.6.3 on Thu Apr 14 07:05:59 2011

import wx

# begin wxGlade: extracode
# end wxGlade



class mainFrame(wx.Frame):
    def __init__(self, *args, **kwds):
        # begin wxGlade: mainFrame.__init__
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)
        self.panelLower = wx.Panel(self, -1)
        self.panelUpper = wx.Panel(self, -1)
        self.sizerPassword_staticbox = wx.StaticBox(self.panelLower, -1, "Password Settings")
        self.sizerInstall_staticbox = wx.StaticBox(self.panelLower, -1, "Install Actions")
        self.sizerStatus_staticbox = wx.StaticBox(self.panelUpper, -1, "Status")
        self.listStatus = wx.ListCtrl(self.panelUpper, -1, style=wx.LC_REPORT|wx.SUNKEN_BORDER)
        self.list_ctrl_1 = wx.ListCtrl(self.panelLower, -1, style=wx.LC_REPORT|wx.SUNKEN_BORDER)

        self.__set_properties()
        self.__do_layout()
        # end wxGlade

    def __set_properties(self):
        # begin wxGlade: mainFrame.__set_properties
        self.SetTitle("frame_1")
        # end wxGlade

    def __do_layout(self):
        # begin wxGlade: mainFrame.__do_layout
        mainSizer = wx.GridSizer(2, 1, 0, 0)
        sizerLower = wx.GridSizer(1, 2, 0, 0)
        sizerInstall = wx.StaticBoxSizer(self.sizerInstall_staticbox, wx.HORIZONTAL)
        sizerInstallButtons = wx.GridSizer(1, 2, 0, 0)
        sizer_4 = wx.BoxSizer(wx.VERTICAL)
        sizerPassword = wx.StaticBoxSizer(self.sizerPassword_staticbox, wx.HORIZONTAL)
        sizerPasswordButtons = wx.GridSizer(3, 8, 0, 0)
        sizerStatus = wx.StaticBoxSizer(self.sizerStatus_staticbox, wx.VERTICAL)
        sizerStatus.Add(self.listStatus, 1, wx.EXPAND, 0)
        self.panelUpper.SetSizer(sizerStatus)
        mainSizer.Add(self.panelUpper, 1, wx.EXPAND, 0)
        sizerPassword.Add(sizerPasswordButtons, 1, wx.EXPAND, 0)
        sizerLower.Add(sizerPassword, 1, wx.EXPAND, 0)
        sizerInstallButtons.Add(self.list_ctrl_1, 1, wx.EXPAND, 0)
        sizerInstallButtons.Add(sizer_4, 1, wx.EXPAND, 0)
        sizerInstall.Add(sizerInstallButtons, 1, wx.EXPAND, 0)
        sizerLower.Add(sizerInstall, 1, wx.EXPAND, 0)
        self.panelLower.SetSizer(sizerLower)
        mainSizer.Add(self.panelLower, 1, wx.EXPAND, 0)
        self.SetSizer(mainSizer)
        mainSizer.Fit(self)
        self.Layout()
        # end wxGlade

# end of class mainFrame


if __name__ == "__main__":
    app = wx.PySimpleApp(0)
    wx.InitAllImageHandlers()
    mainFrame = mainFrame(None, -1, "")
    app.SetTopWindow(mainFrame)
    mainFrame.Show()
    app.MainLoop()

2 个答案:

答案 0 :(得分:0)

喜欢这个吗?

import wx


class Frame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__ (self, None)
        self.SetBackgroundColour(wx.GREEN)

        bSizer1 = wx.BoxSizer(wx.VERTICAL)

        panel1 = wx.Panel(self)
        bSizer1.Add(panel1, 1, wx.EXPAND | wx.ALL, 5)

        bSizer2 = wx.BoxSizer(wx.HORIZONTAL)

        panel2 = wx.Panel(self, size=(-1, 50))
        bSizer2.Add(panel2, 1, wx.EXPAND | wx.ALL, 5)

        panel3 = wx.Panel(self, size=(-1, 50))
        bSizer2.Add(panel3, 1, wx.EXPAND | wx.ALL, 5)

        bSizer1.Add(bSizer2, 0, wx.EXPAND, 5)

        self.SetSizer(bSizer1)


app = wx.PySimpleApp()
app.TopWindow = f = Frame()
f.Show()
app.MainLoop()

Screenshot

答案 1 :(得分:0)

import wx

class MainWindow(wx.Frame):
    def __init__(self, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)
        self.panel1 = wx.Panel(self)
        self.panel1.SetBackgroundColour(wx.GREEN)
        self.panel2 = wx.Panel(self)
        self.panel2.SetBackgroundColour(wx.RED)
        self.panel3 = wx.Panel(self)
        self.panel3.SetBackgroundColour(wx.WHITE)

        self.sizer1 = wx.BoxSizer()
        self.sizer2 = wx.BoxSizer(wx.VERTICAL)
        self.sizer1.Add(self.panel1, proportion=1, flag=wx.EXPAND)
        self.sizer1.Add(self.panel2, proportion=1, flag=wx.EXPAND)
        self.sizer2.Add(self.panel3, proportion=1, flag=wx.EXPAND)
        self.sizer2.Add(self.sizer1, proportion=0, flag=wx.EXPAND)

        self.SetSizerAndFit(self.sizer2)       
        self.Show()

app = wx.App(False)
win = MainWindow(None)
app.MainLoop()