我正在制作wxPython框架。当框架显示下一个面板时,即使使用相同的布局,下一个面板的布局也会被破坏。
代码如下。
有人有什么主意吗?
def _setup(self):
# frame
self.frame = wx.Frame(None, wx.ID_ANY, 'widget', size=(self.Size.WIDTH, self.Size.HEIGHT))
# panel1
self.panel1 = self._get_panel()
self.panel1.Show()
# setting panel
self.panel2 = self._get_panel()
self.panel2.Hide()
self.frame.Show()
def _get_panel(self):
panel = wx.Panel(self.frame, wx.ID_ANY, pos=(0, self.Size.MENU), size=(self.Size.WIDTH, self.Size.HEIGHT - self.Size.MENU))
layout = wx.BoxSizer(wx.VERTICAL)
token_label = wx.StaticText(panel, wx.ID_ANY, 'test')
token_label.SetForegroundColour('#FFFFFF')
layout.Add(token_label, flag=wx.TOP | wx.LEFT, border=self.Size.MARGIN)
self._border(panel, layout)
self.token_text = wx.TextCtrl(panel, wx.ID_ANY, style=wx.TE_LEFT)
self.token_text.SetForegroundColour('#FFFFFF')
self.token_text.SetBackgroundColour('#333333')
layout.Add(self.token_text, flag=wx.GROW | wx.TOP | wx.LEFT | wx.RIGHT, border=self.Size.MARGIN)
panel.SetSizer(layout)
self.btn_panel = wx.Panel(panel, 1, pos=(0, 380), size=(self.Size.WIDTH, 100))
self.btn_panel.SetBackgroundColour('#5DFF3E')
self.btn_panel.Bind(wx.EVT_LEFT_UP, self.clicked)
def clicked(self, event):
self.panel1.Hide()
self.panel2.Show()
答案 0 :(得分:0)
我需要在设置程序中设置sizer。
def _setup(self):
# frame
self.frame = wx.Frame(None, wx.ID_ANY, 'widget', size=(self.Size.WIDTH, self.Size.HEIGHT))
# panel1
self.panel1 = self._get_panel()
self.panel1.Show()
# setting panel
self.panel2 = self._get_panel()
self.panel2.Hide()
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.sizer.Add(self.panel1, 1, wx.EXPAND)
self.sizer.Add(self.panel2, 1, wx.EXPAND)
self.SetSizer(self.sizer)
self.frame.Show()
当我切换面板时,我需要调用框架的布局功能。
def clicked(self, event):
self.panel1.Hide()
self.panel2.Show()
self.frame.Layout()
谢谢。