在Microsoft Windows中将框架捕捉到屏幕一侧时,wx.scrolled窗口中的wxpython GridBagSizer无法正确调整大小

在Microsoft Windows中将框架捕捉到屏幕一侧时,wx.scrolled窗口中的wxpython GridBagSizer无法正确调整大小,python,wxpython,Python,Wxpython,编辑:这似乎只发生在MS Windows 7 Pro和MS Windows 7 Home中。这在Ubuntu 10.04中不会发生 下面是我遇到的问题的一些示例代码: import wx as wx class MainFrame(wx.Frame): def __init__(self, *args, **kwargs): wx.Frame.__init__(self, *args, **kwargs) #Panel that holds all t

编辑:这似乎只发生在MS Windows 7 Pro和MS Windows 7 Home中。这在Ubuntu 10.04中不会发生

下面是我遇到的问题的一些示例代码:

import wx as wx

class MainFrame(wx.Frame):
    def __init__(self, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)

        #Panel that holds all the other panels
        self.mainPanel = wx.ScrolledWindow(self, -1)
        self.mainPanel.SetScrollbars(1, 1, 1, 1)
        self.mainPanel.SetBackgroundColour("LIGHT GREY")

        #Panels in mainPanel
        self.lefttopPanel = wx.Panel(self.mainPanel, -1)
        self.lefttopPanel.SetBackgroundColour("WHITE")        
        self.sizewidgets(self.panelwidgets(
                         text='Left Top Panel', 
                         num=12,
                         parent=self.lefttopPanel),
                         parent=self.lefttopPanel)        

        self.leftmiddlePanel = wx.Panel(self.mainPanel, -1)
        self.leftmiddlePanel.SetBackgroundColour("WHITE")        
        self.sizewidgets(self.panelwidgets(
                         text='Left Middle Panel',
                         num=6,
                         parent=self.leftmiddlePanel),
                         parent=self.leftmiddlePanel)

        self.leftbottomPanel = wx.Panel(self.mainPanel, -1)
        self.leftbottomPanel.SetBackgroundColour("WHITE")
        self.sizewidgets(self.panelwidgets(
                         text='Left Bottom Panel',
                         num=8,
                         parent=self.leftbottomPanel),
                         parent=self.leftbottomPanel)

        self.righttopPanel = wx.Panel(self.mainPanel, -1)
        self.righttopPanel.SetBackgroundColour("WHITE")        
        self.sizewidgets(self.panelwidgets(
                         text='Right Top Panel',
                         num=8,
                         parent=self.righttopPanel),
                         parent=self.righttopPanel)

        self.rightbottomPanel = wx.Panel(self.mainPanel, -1)
        self.rightbottomPanel.SetBackgroundColour("WHITE")
        self.sizewidgets(self.panelwidgets(
                         text='Right Bottom Panel',
                         num=8,
                         parent=self.rightbottomPanel),
                         parent=self.rightbottomPanel)


        mpsizer = wx.GridBagSizer(vgap=4, hgap=4)
        mpsizer.Add(self.lefttopPanel, pos=(0,0), span=(1,1), flag=wx.EXPAND)
        mpsizer.Add(self.leftmiddlePanel, pos=(1,0), span=(1,1), flag=wx.EXPAND)
        mpsizer.Add(self.leftbottomPanel, pos=(2,0), span=(1,2), flag=wx.EXPAND)
        mpsizer.Add(self.righttopPanel, pos=(0,1), span=(2,2), flag=wx.EXPAND)
        mpsizer.Add(self.rightbottomPanel, pos=(2,2), span=(1,1), flag=wx.EXPAND)
        mpsizer.AddGrowableCol(1)
        mpsizer.AddGrowableRow(1)
        self.mainPanel.SetSizer(mpsizer)

        #Adding a refresh to resize event
        self.Bind(wx.EVT_SIZE, self.OnResize)

        self.Show()

    def OnResize(self, event):
        self.Refresh()
        event.Skip()

    def sizewidgets(self, widgetlist , parent):
        psizer = wx.GridSizer(cols=2, vgap=5,hgap=5)
        for widget in widgetlist:
            psizer.Add(widget)
        parent.SetSizer(psizer)



    def panelwidgets(self, text, num, parent):
        widgets = []
        for i in range(num):
            widgets += [wx.StaticText(parent, label=text)]
        return widgets

if __name__ == "__main__":
    app = wx.App()
    MainFrame(None, size=(800, 800), title="GridBagSizer Problem")
    app.MainLoop()
如果不刷新EVT_大小,则会导致某些小部件绘制错误。下面是一个它看起来像什么的示例()

如果将刷新添加到EVT_大小,则会修复大多数大小调整问题,但在MS Windows中将框架捕捉到屏幕的一半时除外。下面是一个这样的示例()

我不明白的是为什么它一直错误地绘制右下面板。它看起来像是从面板的底部而不是顶部绘制的。如果您调整了框架的大小,它会正确地重新绘制它,并为您提供预期的行为


似乎是GrowtableColumn导致了这个问题,但我似乎无法修复它并保持我想要的行为。我尝试在调整大小时调用self.bottomrightPanel.Layout(),但这似乎没有任何作用。我还尝试在resize上调用self.bottomrightPanel.Fit(),这解决了将框架捕捉到屏幕一半时出现的问题,但它会破坏主面板的外观(这导致它看起来非常糟糕)。如果有人知道如何解决这个问题(不改变我在当前应用程序中已经做过的施胶器类型),我将非常感激

我现在也有类似的问题。我已经把它缩小到wx.scrolled窗口。如果您可以将其更改为wx.Panel,则问题可能会得到解决。我仍在研究解决滚动窗口问题