[英]wxpython GridBagSizer inside a wx.ScrolledWindow not resizing correctly when you snap the Frame to a side of the screen in Microsoft Windows
编辑:这似乎仅在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_SIZE,它会导致某些窗口小部件无法正确绘制。 这是一个外观示例( http://i.stack.imgur.com/tYEF4.png )。
如果将刷新添加到EVT_SIZE,则可以解决大多数调整大小的问题,除非在Microsoft Windows中将Frame捕捉到屏幕的一半时。 这是一个看起来像这样的示例( http://i.stack.imgur.com/UKTPi.png )。
我不知道的是为什么它会不断错误地绘制bottomrightPanel。 看起来它是从该面板的底部而不是顶部绘制的。 如果您完全调整框架的大小,它将正确地重新绘制它,并为您提供预期的行为。
似乎growablecolumn引起了问题,但我似乎无法修复它并保持我想要的行为。 我试图在调整大小时调用self.bottomrightPanel.Layout(),但这似乎无济于事。 我还尝试了在调整大小时调用self.bottomrightPanel.Fit(),从而解决了将Frame捕捉到屏幕一半时出现的问题,但它弄乱了mainPanel的外观(这使它看起来确实很糟糕)。 如果那里有人知道如何解决该问题(无需更改我在当前应用中已经完成的sizer类型),我将非常感激。
我现在有一个类似的问题。 我将其范围缩小到wx.ScrolledWindow。 如果您可以将其更改为wx.Panel,则可能会解决此问题。 我仍在寻找解决滚动窗口问题的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.