WxPython-动态添加行的面板不适合框架
我有一个内置3个面板的BoxSizer:WxPython-动态添加行的面板不适合框架,python,wxpython,Python,Wxpython,我有一个内置3个面板的BoxSizer: 标题栏 带有GridBagSizer的可滚动面板 背面按钮面板 我在GridBagSizer中动态添加行,但它不适合面板中的可用空间。 手动调整框架大小后,它就适合了! 我试着把.Layout放在任何地方,但没有结果 我的代码: import wx import wx.lib.scrolledpanel as scrolled class Myframe(wx.Frame):
.Layout
放在任何地方,但没有结果
我的代码:
import wx
import wx.lib.scrolledpanel as scrolled
class Myframe(wx.Frame): # Create Frame
def __init__(self):
wx.Frame.__init__(self, None, title="List")
self.Center()
a = self.GetSize()
MyContainerMenu(self) # Main Menu
self.Layout()
class MyContainerMenu(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent, size=(513, 728), style=wx.FULL_REPAINT_ON_RESIZE)
e = wx.Button(self, label="Show list")
panelloc = wx.BoxSizer(wx.HORIZONTAL)
panelloc.AddStretchSpacer()
panelloc.Add(e, 0, wx.ALIGN_CENTER_VERTICAL)
panelloc.AddStretchSpacer()
self.SetSizer(panelloc)
self.Layout()
e.Bind(wx.EVT_BUTTON, self.DeleteChar, e)
self.Layout()
panelloc.Layout()
def DeleteChar(self, event): # Destroy Main Menu and creates the list
c = self.GetParent()
self.Destroy()
MyContainerPanel(c, c.GetSize())
class MyContainerPanel(wx.Panel):
def __init__(self, parent, size):
wx.Panel.__init__(self, parent, size=size)
twopanel = wx.BoxSizer(wx.VERTICAL)
a = MyPanelA(self) # Title goes here
b = MyPanel(self) # List with scroll bar
bakk = wx.Button(self, label="Back") # "Back" button goes here
twopanel.Add(a, 0, wx.EXPAND)
twopanel.Add(b, 1, wx.EXPAND)
twopanel.Add(bakk, 0, wx.EXPAND)
self.SetSizer(twopanel)
self.Layout()
twopanel.Layout()
class MyPanelA(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent, size=(120, 120))
self.SetBackgroundColour((30, 18, 18))
title_del = wx.StaticText(self, size=(20, 30), label="TITLE", style=wx.ALIGN_CENTRE_HORIZONTAL)
title_del.SetForegroundColour('goldenrod')
siz = wx.BoxSizer(wx.HORIZONTAL)
siz.Add(title_del, 1, wx.EXPAND|wx.ALL)
self.SetSizerAndFit(siz)
class MyPanel(scrolled.ScrolledPanel): # PAnel with scroll
def __init__(self, parent):
scrolled.ScrolledPanel.__init__(self, parent)
self.SetBackgroundColour((58, 18, 18))
self.SetAutoLayout(1)
self.SetupScrolling()
f = wx.GridBagSizer(100, 40)
self.SetSizer(f)
ub = 0 # Add rows into the sizer dinamically
names = ["Curly", "Moe", "Larry", "Shemp", "Joe", "Michelangelo", "Raphael", "Donatello", "Leonardo"]
for x in names:
a = wx.StaticText(self, label=x, style=wx.EXPAND)
f.Add(a, pos=(ub, 1))
ub += 1
self.Layout()
f.Layout()
class App(wx.App):
def OnInit(self):
self.frame = Myframe()
self.frame.Show()
self.SetTopWindow(self.frame)
return True
app = App()
app.MainLoop()
编辑:
这就是我得到的:
这是在我手动调整框架大小之后。注意滚动条和“后退”按钮
您可以发布数据
不适合和适合的屏幕截图吗。(您可以在问题中添加图像)您是否可以发布数据不符合
和符合
的屏幕截图。(您可以在问题中添加图像)