wxpython + 更改面板和重做布局面板后非常小
wxpython + after changing panel and redo layout panel is very small
我通过破坏面板 1 然后显示面板 2 来更改我的面板。我不能使用创建两者和隐藏显示的方法,因为我还有其他问题。但是重做布局后,我的面板非常小。我怎样才能让它和以前一样大?
这是我的测试代码
import wx
class Main(wx.Frame):
def __init__(self, parent=None, id=-1, notify_channel="chanMicroanalysis", **kwargs):
# general panel information
wx.Frame.__init__(self, parent, wx.ID_ANY)
self.SetTitle('Microanalysis')
self.backpanel = wx.Panel(self, wx.ID_ANY)
# first panel
self.Choicepanel = wx.Panel(self.backpanel, wx.ID_ANY)
self.lblChoose = wx.StaticText(self.Choicepanel, label="Choose:")
self.btnChooseFilterOnly = wx.Button(self.Choicepanel, wx.ID_ANY, "Filter only ")
self.btnChooseMA = wx.Button(self.Choicepanel, wx.ID_ANY, "Microanalyse")
self.btnChooseCellInfo = wx.Button(self.Choicepanel, wx.ID_ANY, " CellInfo ")
self.btnChooseReport = wx.Button(self.Choicepanel, wx.ID_ANY, "Report")
# second panel: cellinfo
self.test1 =wx.Panel(self.backpanel, wx.ID_ANY)
self.Cellinfopanel = self.test1
self.lblChooseingo = wx.StaticText(self.Cellinfopanel, label="Choose:")
self.btnChooseFilter = wx.Button(self.Cellinfopanel, wx.ID_ANY, "Filter only ")
self.btnChooseprr = wx.Button(self.Cellinfopanel, wx.ID_ANY, "Microanalyse")
self.btnChooseCell = wx.Button(self.Cellinfopanel, wx.ID_ANY, " CellInfo ")
self.btnChoose = wx.Button(self.Cellinfopanel, wx.ID_ANY, "Report")
self._do_layout()
self._do_bindings()
def _do_layout(self):
self.h_main_sizer = wx.BoxSizer()
self.h_centerbuttonsizer = wx.BoxSizer()
self.h_centerbutton1sizer = wx.BoxSizer()
self.v_firstsizer = wx.BoxSizer(wx.VERTICAL)
self.v_secondsizer = wx.BoxSizer(wx.VERTICAL)
self.v_thirdsizer = wx.BoxSizer(wx.VERTICAL)
self.v_fourthsizer = wx.BoxSizer(wx.VERTICAL)
self.v_buttonsizer = wx.BoxSizer(wx.VERTICAL)
self.v_button1sizer = wx.BoxSizer(wx.VERTICAL)
########################################"
self.v_firstsizer.Add(self.Choicepanel, 1, wx.EXPAND)
self.v_buttonsizer.Add(self.lblChoose, 0, wx.CENTER)
self.v_buttonsizer.Add(self.btnChooseFilterOnly, 0, wx.EXPAND)
self.v_buttonsizer.Add(self.btnChooseMA, 0, wx.EXPAND)
self.v_buttonsizer.Add(self.btnChooseCellInfo, 0, wx.EXPAND)
self.v_buttonsizer.Add(self.btnChooseReport, 0, wx.EXPAND)
self.h_centerbuttonsizer.AddStretchSpacer(1)
self.h_centerbuttonsizer.Add(self.v_buttonsizer, 0, wx.CENTER)
self.h_centerbuttonsizer.AddStretchSpacer(1)
self.Choicepanel.SetSizer(self.h_centerbuttonsizer)
self.h_centerbuttonsizer.Fit(self.Choicepanel)
########################################"
self.v_secondsizer.Add(self.Cellinfopanel, 5, wx.EXPAND)
self.v_button1sizer.Add(self.lblChooseingo, 0, wx.CENTER)
self.v_button1sizer.Add(self.btnChooseFilter, 0, wx.EXPAND)
self.v_button1sizer.Add(self.btnChooseprr, 0, wx.EXPAND)
self.v_button1sizer.Add(self.btnChooseCell, 0, wx.EXPAND)
self.v_button1sizer.Add(self.btnChoose, 0, wx.EXPAND)
self.h_centerbutton1sizer.AddStretchSpacer(1)
self.h_centerbutton1sizer.Add(self.v_button1sizer, 0, wx.CENTER)
self.h_centerbutton1sizer.AddStretchSpacer(1)
self.Cellinfopanel.SetSizer(self.h_centerbutton1sizer)
self.h_centerbutton1sizer.Fit(self.Choicepanel)
########################################"
self.h_main_sizer.Add(self.v_firstsizer, 20, wx.EXPAND)
self.h_main_sizer.Add(self.v_secondsizer, 20, wx.EXPAND)
self.backpanel.SetSizer(self.h_main_sizer)
self.h_main_sizer.Fit(self)
#
# self.Choicepanel.Show()
# self.Cellinfopanel.Hide()
# self.MApanel.Hide()
# self.Reportpanel.Hide()
self.Choicepanel.Show()
self.Cellinfopanel.Show()
self.statusMAPanelShown = False
def _do_bindings(self):
self.btnChooseprr.Bind(wx.EVT_BUTTON, self.on_chooseMA)
def on_chooseMA(self, event):
print "in choose MA"
self.showMAPanel()
self._do_layout()
#
# self.Layout()
def showMAPanel(self):
print "in showmapanel"
self.test1.Destroy()
self.test2 =wx.Panel(self.backpanel, wx.ID_ANY)
self.Cellinfopanel = self.test2
self.lblChooseingo = wx.StaticText(self.Cellinfopanel, label="test:")
self.btnChooseFilter = wx.Button(self.Cellinfopanel, wx.ID_ANY, "test1 ")
self.btnChooseprr = wx.Button(self.Cellinfopanel, wx.ID_ANY, "test2")
self.btnChooseCell = wx.Button(self.Cellinfopanel, wx.ID_ANY, " test3 ")
self.btnChoose = wx.Button(self.Cellinfopanel, wx.ID_ANY, "test4")
if __name__ == '__main__':
app = wx.PySimpleApp()
MAview = Main(None, wx.ID_ANY)
MAview.Maximize()
MAview.Show()
app.MainLoop()
编辑:这与提议的问题不同。提题中,我用的是hide and show的方式,也有resizing的问题,就是panel太大了。我其实解决了另一个问题,我会添加答案。
这个 post 帮助我解决了我的问题 (http://forums.devshed.com/python-programming-11/wxpython-refreshing-panel-panel-392700.html)
加上
self.Fit()
self.GetParent().SendSizeEvent()
我的问题解决了。
我通过破坏面板 1 然后显示面板 2 来更改我的面板。我不能使用创建两者和隐藏显示的方法,因为我还有其他问题。但是重做布局后,我的面板非常小。我怎样才能让它和以前一样大?
这是我的测试代码
import wx
class Main(wx.Frame):
def __init__(self, parent=None, id=-1, notify_channel="chanMicroanalysis", **kwargs):
# general panel information
wx.Frame.__init__(self, parent, wx.ID_ANY)
self.SetTitle('Microanalysis')
self.backpanel = wx.Panel(self, wx.ID_ANY)
# first panel
self.Choicepanel = wx.Panel(self.backpanel, wx.ID_ANY)
self.lblChoose = wx.StaticText(self.Choicepanel, label="Choose:")
self.btnChooseFilterOnly = wx.Button(self.Choicepanel, wx.ID_ANY, "Filter only ")
self.btnChooseMA = wx.Button(self.Choicepanel, wx.ID_ANY, "Microanalyse")
self.btnChooseCellInfo = wx.Button(self.Choicepanel, wx.ID_ANY, " CellInfo ")
self.btnChooseReport = wx.Button(self.Choicepanel, wx.ID_ANY, "Report")
# second panel: cellinfo
self.test1 =wx.Panel(self.backpanel, wx.ID_ANY)
self.Cellinfopanel = self.test1
self.lblChooseingo = wx.StaticText(self.Cellinfopanel, label="Choose:")
self.btnChooseFilter = wx.Button(self.Cellinfopanel, wx.ID_ANY, "Filter only ")
self.btnChooseprr = wx.Button(self.Cellinfopanel, wx.ID_ANY, "Microanalyse")
self.btnChooseCell = wx.Button(self.Cellinfopanel, wx.ID_ANY, " CellInfo ")
self.btnChoose = wx.Button(self.Cellinfopanel, wx.ID_ANY, "Report")
self._do_layout()
self._do_bindings()
def _do_layout(self):
self.h_main_sizer = wx.BoxSizer()
self.h_centerbuttonsizer = wx.BoxSizer()
self.h_centerbutton1sizer = wx.BoxSizer()
self.v_firstsizer = wx.BoxSizer(wx.VERTICAL)
self.v_secondsizer = wx.BoxSizer(wx.VERTICAL)
self.v_thirdsizer = wx.BoxSizer(wx.VERTICAL)
self.v_fourthsizer = wx.BoxSizer(wx.VERTICAL)
self.v_buttonsizer = wx.BoxSizer(wx.VERTICAL)
self.v_button1sizer = wx.BoxSizer(wx.VERTICAL)
########################################"
self.v_firstsizer.Add(self.Choicepanel, 1, wx.EXPAND)
self.v_buttonsizer.Add(self.lblChoose, 0, wx.CENTER)
self.v_buttonsizer.Add(self.btnChooseFilterOnly, 0, wx.EXPAND)
self.v_buttonsizer.Add(self.btnChooseMA, 0, wx.EXPAND)
self.v_buttonsizer.Add(self.btnChooseCellInfo, 0, wx.EXPAND)
self.v_buttonsizer.Add(self.btnChooseReport, 0, wx.EXPAND)
self.h_centerbuttonsizer.AddStretchSpacer(1)
self.h_centerbuttonsizer.Add(self.v_buttonsizer, 0, wx.CENTER)
self.h_centerbuttonsizer.AddStretchSpacer(1)
self.Choicepanel.SetSizer(self.h_centerbuttonsizer)
self.h_centerbuttonsizer.Fit(self.Choicepanel)
########################################"
self.v_secondsizer.Add(self.Cellinfopanel, 5, wx.EXPAND)
self.v_button1sizer.Add(self.lblChooseingo, 0, wx.CENTER)
self.v_button1sizer.Add(self.btnChooseFilter, 0, wx.EXPAND)
self.v_button1sizer.Add(self.btnChooseprr, 0, wx.EXPAND)
self.v_button1sizer.Add(self.btnChooseCell, 0, wx.EXPAND)
self.v_button1sizer.Add(self.btnChoose, 0, wx.EXPAND)
self.h_centerbutton1sizer.AddStretchSpacer(1)
self.h_centerbutton1sizer.Add(self.v_button1sizer, 0, wx.CENTER)
self.h_centerbutton1sizer.AddStretchSpacer(1)
self.Cellinfopanel.SetSizer(self.h_centerbutton1sizer)
self.h_centerbutton1sizer.Fit(self.Choicepanel)
########################################"
self.h_main_sizer.Add(self.v_firstsizer, 20, wx.EXPAND)
self.h_main_sizer.Add(self.v_secondsizer, 20, wx.EXPAND)
self.backpanel.SetSizer(self.h_main_sizer)
self.h_main_sizer.Fit(self)
#
# self.Choicepanel.Show()
# self.Cellinfopanel.Hide()
# self.MApanel.Hide()
# self.Reportpanel.Hide()
self.Choicepanel.Show()
self.Cellinfopanel.Show()
self.statusMAPanelShown = False
def _do_bindings(self):
self.btnChooseprr.Bind(wx.EVT_BUTTON, self.on_chooseMA)
def on_chooseMA(self, event):
print "in choose MA"
self.showMAPanel()
self._do_layout()
#
# self.Layout()
def showMAPanel(self):
print "in showmapanel"
self.test1.Destroy()
self.test2 =wx.Panel(self.backpanel, wx.ID_ANY)
self.Cellinfopanel = self.test2
self.lblChooseingo = wx.StaticText(self.Cellinfopanel, label="test:")
self.btnChooseFilter = wx.Button(self.Cellinfopanel, wx.ID_ANY, "test1 ")
self.btnChooseprr = wx.Button(self.Cellinfopanel, wx.ID_ANY, "test2")
self.btnChooseCell = wx.Button(self.Cellinfopanel, wx.ID_ANY, " test3 ")
self.btnChoose = wx.Button(self.Cellinfopanel, wx.ID_ANY, "test4")
if __name__ == '__main__':
app = wx.PySimpleApp()
MAview = Main(None, wx.ID_ANY)
MAview.Maximize()
MAview.Show()
app.MainLoop()
编辑:这与提议的问题不同。提题中,我用的是hide and show的方式,也有resizing的问题,就是panel太大了。我其实解决了另一个问题,我会添加答案。
这个 post 帮助我解决了我的问题 (http://forums.devshed.com/python-programming-11/wxpython-refreshing-panel-panel-392700.html)
加上
self.Fit()
self.GetParent().SendSizeEvent()
我的问题解决了。