[英]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.