为什么 Treebook 中的 ScrolledPanel 不会自动调整大小?
Why is a ScrolledPanel inside a Treebook not resized automatically?
因为我需要滚动条,所以我用 ScrolledPanel 更改了默认面板,但是我在 ScrolledPanel 中插入的内容不会使其根据 window 的大小自动调整大小。
然后我尝试创建一个默认面板并通过 BoxSizer 将所有小部件插入其中,最后通过另一个 BoxSizer 将此面板插入到 ScrolledPanel 中,但内容继续,但没有进行自动调整大小。
我也尝试了相反的方法,即我创建了一个标准面板并使用 BoxSizers 插入到我的 ScrolledPanel 中,但也没有用。
另外一个细节就是这个ScrolledPanels必须在一个TreeBook里面,因为我有一个tree来管理每个ScrolledPanel的调用。
我的代码:
import wx
import wx.lib.scrolledpanel as scrolled
from gettext import gettext as _
class MyMainView(wx.Frame):
instance = None
init = 0
def __init__(self, app):
if self.init:
return
self.frameWidth = 850
self.frameHeight = 600
self.init = 1
no_sys_menu = wx.MINIMIZE_BOX | wx.MAXIMIZE_BOX | wx.CAPTION | wx.CLIP_CHILDREN | wx.CLOSE_BOX
wx.Frame.__init__(self, None, title=_("Title"), style=no_sys_menu)
self.SetSize(wx.Size(self.frameWidth, self.frameHeight))
self.SetBackgroundColour('white')
self.Centre()
treeBook = Treebook(self)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(treeBook, 1, wx.ALL | wx.EXPAND, 10)
self.SetSizer(sizer)
self.Show()
self.Layout()
def __new__(self, *args, **kwargs):
if self.instance is None:
self.instance = wx.Frame.__new__(self)
elif not self.instance:
self.instance = wx.Frame.__new__(self)
return self.instance
class Treebook(wx.Treebook):
def __init__(self, parent):
wx.Treebook.__init__(self, parent, wx.ID_ANY, style=wx.BK_DEFAULT)
self.AddPage(MainPanel(self), _("AppTitle"))
self.AddSubPage(MenuPanel(self), _("SubNodeTitle1"))
self.ExpandNode(0)
class MainPanel(wx.Panel): # This Panel is OK
def __init__(self, parent):
wx.Panel.__init__(self, parent=parent, id=wx.ID_ANY)
self.font1 = wx.Font(18, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD)
self.font2 = wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL)
self.SetBackgroundColour("white")
pngIcon = wx.Image("foo.ico", wx.BITMAP_TYPE_ANY).ConvertToBitmap()
icon = wx.StaticBitmap(self, -1, pngIcon, pos=(25, 15), size=(pngIcon.GetWidth(), pngIcon.GetHeight()))
titleHelp = wx.StaticText(self, -1, _("HelpTitle"))
titleHelp.SetFont(self.font1)
titleApp = wx.StaticText(self, -1, _("AppTitle"), pos=(25, 85))
titleApp.SetFont(self.font1)
description = wx.StaticText(self, -1, _("App description."), pos=(25, 170))
description.SetFont(self.font2)
features = wx.StaticText(self, -1, _("App features."), pos=(25, 210))
features.SetFont(self.font2)
pngLogo = wx.Image("foo.png", wx.BITMAP_TYPE_ANY).ConvertToBitmap()
logo = wx.StaticBitmap(self, -1, pngLogo, pos=(25, 390), size=(pngLogo.GetWidth(), pngLogo.GetHeight()))
sliLine = wx.StaticLine(self, -1, style=wx.LI_HORIZONTAL)
sliLine.SetSize(wx.Size(625, 1))
steCopy = wx.StaticText(self, -1, _("Copyright text."))
steCopy.SetFont(self.font2)
heigthSpacer = 20
hSizer = wx.BoxSizer(wx.HORIZONTAL)
hSizer.Add(icon, 0, wx.LEFT, 0)
hSizer.Add(titleHelp, 0, wx.LEFT | wx.ALIGN_CENTER_VERTICAL, 10)
vSizer = wx.BoxSizer(wx.VERTICAL)
vSizer.AddSpacer(heigthSpacer)
vSizer.Add(hSizer, 0, wx.LEFT, 10)
vSizer.AddSpacer(heigthSpacer + 10)
vSizer.Add(titleApp, 0, wx.LEFT, 15)
vSizer.AddSpacer(10)
vSizer.Add(description, 0, wx.LEFT, 15)
vSizer.AddSpacer(heigthSpacer)
vSizer.Add(features, 0, wx.LEFT, 15)
vSizer.AddSpacer(115)
vSizer.Add(logo, 0, wx.LEFT, 15)
vSizer.Add(sliLine, 0, wx.TOP | wx.LEFT | wx.RIGHT | wx.EXPAND, 15)
vSizer.Add(steCopy, 0, wx.LEFT | wx.RIGHT | wx.ALIGN_RIGHT, 15)
self.SetSizer(vSizer)
class MenuPanel(scrolled.ScrolledPanel): # This panel does not fit content within the size of the Treebook panel
def __init__(self, parent):
scrolled.ScrolledPanel.__init__(self, parent, -1)
self.SetBackgroundColour("white")
self.font1 = wx.Font(18, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD)
self.font2 = wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL)
self.font3 = wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD)
strTitlePage = wx.StaticText(self, -1, _("TitlePanel"))
strTitlePage.SetFont(self.font1)
strIntroPage = wx.StaticText(self, -1, _("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."))
strIntroPage.SetFont(self.font2)
png = wx.Image("foo.png", wx.BITMAP_TYPE_ANY).ConvertToBitmap()
bitmap1 = wx.StaticBitmap(self, -1, png, pos=(240, 100), size=(png.GetWidth(), png.GetHeight()))
steMainTitle = wx.StaticText(self, -1, _("MainMenu"))
steMainTitle.SetFont(self.font3)
steMainMenu = wx.StaticText(self, -1, _("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."))
steMainMenu.SetFont(self.font2)
png = wx.Image("foo.png", wx.BITMAP_TYPE_ANY).ConvertToBitmap()
bitmap2 = wx.StaticBitmap(self, -1, png, pos=(240, 100), size=(png.GetWidth(), png.GetHeight()))
steLangTitle = wx.StaticText(self, -1, _("Config Menu"))
steLangTitle.SetFont(self.font3)
steLangMenu = wx.StaticText(self, -1, _("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."))
steLangMenu.SetFont(self.font2)
png = wx.Image("foo.png", wx.BITMAP_TYPE_ANY).ConvertToBitmap()
bitmap3 = wx.StaticBitmap(self, -1, png, pos=(240, 100), size=(png.GetWidth(), png.GetHeight()))
stePortMenu = wx.StaticText(self, -1, _("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."))
stePortMenu.SetFont(self.font2)
png = wx.Image("foo.png", wx.BITMAP_TYPE_ANY).ConvertToBitmap()
bitmap4 = wx.StaticBitmap(self, -1, png, pos=(240, 100), size=(png.GetWidth(), png.GetHeight()))
steHelpTitle = wx.StaticText(self, -1, _("Menu Help"))
steHelpTitle.SetFont(self.font3)
steHelpMenu = wx.StaticText(self, -1, _("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."))
steHelpMenu.SetFont(self.font2)
sliLine = wx.StaticLine(self, -1, style=wx.LI_HORIZONTAL)
steCopy = wx.StaticText(self, -1, _("Copyright text."))
steCopy.SetFont(self.font2)
heigthSpacer = 20
vSizer = wx.BoxSizer(wx.VERTICAL)
vSizer.AddSpacer(heigthSpacer)
vSizer.Add(strTitlePage, 0, wx.ALL, 5)
vSizer.Add(strIntroPage, 0, wx.EXPAND, 5)
vSizer.AddSpacer(heigthSpacer)
vSizer.Add(steMainTitle, 0, wx.ALL, 5)
vSizer.Add(bitmap1, 0, wx.ALIGN_CENTRE_HORIZONTAL, 5)
vSizer.Add(steMainMenu, 0, wx.EXPAND, 5)
vSizer.AddSpacer(heigthSpacer)
vSizer.Add(steLangTitle, 0, wx.ALL, 5)
vSizer.Add(bitmap2, 0, wx.ALIGN_CENTRE_HORIZONTAL, 5)
vSizer.Add(steLangMenu, 0, wx.EXPAND, 5)
vSizer.AddSpacer(heigthSpacer)
vSizer.Add(bitmap3, 0, wx.ALIGN_CENTRE_HORIZONTAL, 5)
vSizer.Add(stePortMenu, 0, wx.EXPAND, 5)
vSizer.AddSpacer(heigthSpacer)
vSizer.Add(steHelpTitle, 0, wx.ALL, 5)
vSizer.Add(bitmap4, 0, wx.ALIGN_CENTRE_HORIZONTAL, 5)
vSizer.Add(steHelpMenu, 0, wx.EXPAND, 5)
vSizer.AddSpacer(heigthSpacer)
vSizer.Add(sliLine, 0, wx.ALL | wx.EXPAND, 5)
vSizer.Add(steCopy, 0, wx.ALIGN_RIGHT, 5)
self.SetSizer(vSizer)
self.Layout()
self.SetAutoLayout(1)
self.SetupScrolling()
def main():
app = wx.App(False)
main = MyMainView(app)
app.MainLoop()
if __name__ == '__main__':
main()
我想要的是单击树中的一个项目并打开面板旁边的内容根据我的window(静态文本、静态行)的大小调整大小。
我不确定我是否理解正确但是:
- StaticText 不会自动换行,因此即使 "inner panel" 正确调整大小,文本也不会可见。您可能想使用某种 TextCtrl,可能是富文本 ctrl。
- 如果你有一个滚动面板,那么面板内部有它需要的任何大小,而滚动面板只是添加了滚动条。
所以,您需要做的是:在 MenuPanel 中创建另一个面板,并使 MenuPanel 中的所有小部件成为这个新面板的子项。然后为 MenuPanel
添加一个 on-size 处理程序
self.Bind(wx.EVT_SIZE, self.OnSize)
def OnSize(self, evt):
evt.Skip(False)
self.p.SetSize(evt.GetSize())
(self.p 是 MenuPanel 内的新面板)。但这会设置面板的大小,因此永远不需要滚动条。您可能只需要垂直滚动条,并且只在需要时使用,对吗?然后我可能会尝试仅在可能的情况下设置 window 的宽度,或者设置宽度和非常大的高度,测量并再次设置尺寸。
因为我需要滚动条,所以我用 ScrolledPanel 更改了默认面板,但是我在 ScrolledPanel 中插入的内容不会使其根据 window 的大小自动调整大小。
然后我尝试创建一个默认面板并通过 BoxSizer 将所有小部件插入其中,最后通过另一个 BoxSizer 将此面板插入到 ScrolledPanel 中,但内容继续,但没有进行自动调整大小。
我也尝试了相反的方法,即我创建了一个标准面板并使用 BoxSizers 插入到我的 ScrolledPanel 中,但也没有用。
另外一个细节就是这个ScrolledPanels必须在一个TreeBook里面,因为我有一个tree来管理每个ScrolledPanel的调用。
我的代码:
import wx
import wx.lib.scrolledpanel as scrolled
from gettext import gettext as _
class MyMainView(wx.Frame):
instance = None
init = 0
def __init__(self, app):
if self.init:
return
self.frameWidth = 850
self.frameHeight = 600
self.init = 1
no_sys_menu = wx.MINIMIZE_BOX | wx.MAXIMIZE_BOX | wx.CAPTION | wx.CLIP_CHILDREN | wx.CLOSE_BOX
wx.Frame.__init__(self, None, title=_("Title"), style=no_sys_menu)
self.SetSize(wx.Size(self.frameWidth, self.frameHeight))
self.SetBackgroundColour('white')
self.Centre()
treeBook = Treebook(self)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(treeBook, 1, wx.ALL | wx.EXPAND, 10)
self.SetSizer(sizer)
self.Show()
self.Layout()
def __new__(self, *args, **kwargs):
if self.instance is None:
self.instance = wx.Frame.__new__(self)
elif not self.instance:
self.instance = wx.Frame.__new__(self)
return self.instance
class Treebook(wx.Treebook):
def __init__(self, parent):
wx.Treebook.__init__(self, parent, wx.ID_ANY, style=wx.BK_DEFAULT)
self.AddPage(MainPanel(self), _("AppTitle"))
self.AddSubPage(MenuPanel(self), _("SubNodeTitle1"))
self.ExpandNode(0)
class MainPanel(wx.Panel): # This Panel is OK
def __init__(self, parent):
wx.Panel.__init__(self, parent=parent, id=wx.ID_ANY)
self.font1 = wx.Font(18, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD)
self.font2 = wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL)
self.SetBackgroundColour("white")
pngIcon = wx.Image("foo.ico", wx.BITMAP_TYPE_ANY).ConvertToBitmap()
icon = wx.StaticBitmap(self, -1, pngIcon, pos=(25, 15), size=(pngIcon.GetWidth(), pngIcon.GetHeight()))
titleHelp = wx.StaticText(self, -1, _("HelpTitle"))
titleHelp.SetFont(self.font1)
titleApp = wx.StaticText(self, -1, _("AppTitle"), pos=(25, 85))
titleApp.SetFont(self.font1)
description = wx.StaticText(self, -1, _("App description."), pos=(25, 170))
description.SetFont(self.font2)
features = wx.StaticText(self, -1, _("App features."), pos=(25, 210))
features.SetFont(self.font2)
pngLogo = wx.Image("foo.png", wx.BITMAP_TYPE_ANY).ConvertToBitmap()
logo = wx.StaticBitmap(self, -1, pngLogo, pos=(25, 390), size=(pngLogo.GetWidth(), pngLogo.GetHeight()))
sliLine = wx.StaticLine(self, -1, style=wx.LI_HORIZONTAL)
sliLine.SetSize(wx.Size(625, 1))
steCopy = wx.StaticText(self, -1, _("Copyright text."))
steCopy.SetFont(self.font2)
heigthSpacer = 20
hSizer = wx.BoxSizer(wx.HORIZONTAL)
hSizer.Add(icon, 0, wx.LEFT, 0)
hSizer.Add(titleHelp, 0, wx.LEFT | wx.ALIGN_CENTER_VERTICAL, 10)
vSizer = wx.BoxSizer(wx.VERTICAL)
vSizer.AddSpacer(heigthSpacer)
vSizer.Add(hSizer, 0, wx.LEFT, 10)
vSizer.AddSpacer(heigthSpacer + 10)
vSizer.Add(titleApp, 0, wx.LEFT, 15)
vSizer.AddSpacer(10)
vSizer.Add(description, 0, wx.LEFT, 15)
vSizer.AddSpacer(heigthSpacer)
vSizer.Add(features, 0, wx.LEFT, 15)
vSizer.AddSpacer(115)
vSizer.Add(logo, 0, wx.LEFT, 15)
vSizer.Add(sliLine, 0, wx.TOP | wx.LEFT | wx.RIGHT | wx.EXPAND, 15)
vSizer.Add(steCopy, 0, wx.LEFT | wx.RIGHT | wx.ALIGN_RIGHT, 15)
self.SetSizer(vSizer)
class MenuPanel(scrolled.ScrolledPanel): # This panel does not fit content within the size of the Treebook panel
def __init__(self, parent):
scrolled.ScrolledPanel.__init__(self, parent, -1)
self.SetBackgroundColour("white")
self.font1 = wx.Font(18, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD)
self.font2 = wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL)
self.font3 = wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD)
strTitlePage = wx.StaticText(self, -1, _("TitlePanel"))
strTitlePage.SetFont(self.font1)
strIntroPage = wx.StaticText(self, -1, _("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."))
strIntroPage.SetFont(self.font2)
png = wx.Image("foo.png", wx.BITMAP_TYPE_ANY).ConvertToBitmap()
bitmap1 = wx.StaticBitmap(self, -1, png, pos=(240, 100), size=(png.GetWidth(), png.GetHeight()))
steMainTitle = wx.StaticText(self, -1, _("MainMenu"))
steMainTitle.SetFont(self.font3)
steMainMenu = wx.StaticText(self, -1, _("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."))
steMainMenu.SetFont(self.font2)
png = wx.Image("foo.png", wx.BITMAP_TYPE_ANY).ConvertToBitmap()
bitmap2 = wx.StaticBitmap(self, -1, png, pos=(240, 100), size=(png.GetWidth(), png.GetHeight()))
steLangTitle = wx.StaticText(self, -1, _("Config Menu"))
steLangTitle.SetFont(self.font3)
steLangMenu = wx.StaticText(self, -1, _("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."))
steLangMenu.SetFont(self.font2)
png = wx.Image("foo.png", wx.BITMAP_TYPE_ANY).ConvertToBitmap()
bitmap3 = wx.StaticBitmap(self, -1, png, pos=(240, 100), size=(png.GetWidth(), png.GetHeight()))
stePortMenu = wx.StaticText(self, -1, _("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."))
stePortMenu.SetFont(self.font2)
png = wx.Image("foo.png", wx.BITMAP_TYPE_ANY).ConvertToBitmap()
bitmap4 = wx.StaticBitmap(self, -1, png, pos=(240, 100), size=(png.GetWidth(), png.GetHeight()))
steHelpTitle = wx.StaticText(self, -1, _("Menu Help"))
steHelpTitle.SetFont(self.font3)
steHelpMenu = wx.StaticText(self, -1, _("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."))
steHelpMenu.SetFont(self.font2)
sliLine = wx.StaticLine(self, -1, style=wx.LI_HORIZONTAL)
steCopy = wx.StaticText(self, -1, _("Copyright text."))
steCopy.SetFont(self.font2)
heigthSpacer = 20
vSizer = wx.BoxSizer(wx.VERTICAL)
vSizer.AddSpacer(heigthSpacer)
vSizer.Add(strTitlePage, 0, wx.ALL, 5)
vSizer.Add(strIntroPage, 0, wx.EXPAND, 5)
vSizer.AddSpacer(heigthSpacer)
vSizer.Add(steMainTitle, 0, wx.ALL, 5)
vSizer.Add(bitmap1, 0, wx.ALIGN_CENTRE_HORIZONTAL, 5)
vSizer.Add(steMainMenu, 0, wx.EXPAND, 5)
vSizer.AddSpacer(heigthSpacer)
vSizer.Add(steLangTitle, 0, wx.ALL, 5)
vSizer.Add(bitmap2, 0, wx.ALIGN_CENTRE_HORIZONTAL, 5)
vSizer.Add(steLangMenu, 0, wx.EXPAND, 5)
vSizer.AddSpacer(heigthSpacer)
vSizer.Add(bitmap3, 0, wx.ALIGN_CENTRE_HORIZONTAL, 5)
vSizer.Add(stePortMenu, 0, wx.EXPAND, 5)
vSizer.AddSpacer(heigthSpacer)
vSizer.Add(steHelpTitle, 0, wx.ALL, 5)
vSizer.Add(bitmap4, 0, wx.ALIGN_CENTRE_HORIZONTAL, 5)
vSizer.Add(steHelpMenu, 0, wx.EXPAND, 5)
vSizer.AddSpacer(heigthSpacer)
vSizer.Add(sliLine, 0, wx.ALL | wx.EXPAND, 5)
vSizer.Add(steCopy, 0, wx.ALIGN_RIGHT, 5)
self.SetSizer(vSizer)
self.Layout()
self.SetAutoLayout(1)
self.SetupScrolling()
def main():
app = wx.App(False)
main = MyMainView(app)
app.MainLoop()
if __name__ == '__main__':
main()
我想要的是单击树中的一个项目并打开面板旁边的内容根据我的window(静态文本、静态行)的大小调整大小。
我不确定我是否理解正确但是:
- StaticText 不会自动换行,因此即使 "inner panel" 正确调整大小,文本也不会可见。您可能想使用某种 TextCtrl,可能是富文本 ctrl。
- 如果你有一个滚动面板,那么面板内部有它需要的任何大小,而滚动面板只是添加了滚动条。
所以,您需要做的是:在 MenuPanel 中创建另一个面板,并使 MenuPanel 中的所有小部件成为这个新面板的子项。然后为 MenuPanel
添加一个 on-size 处理程序 self.Bind(wx.EVT_SIZE, self.OnSize)
def OnSize(self, evt):
evt.Skip(False)
self.p.SetSize(evt.GetSize())
(self.p 是 MenuPanel 内的新面板)。但这会设置面板的大小,因此永远不需要滚动条。您可能只需要垂直滚动条,并且只在需要时使用,对吗?然后我可能会尝试仅在可能的情况下设置 window 的宽度,或者设置宽度和非常大的高度,测量并再次设置尺寸。