更改面板和重做布局面板后的wxpython +非常小

时间:2017-02-21 10:49:20

标签: resize wxpython panels

我通过销毁面板1然后显示面板2来更改我的面板。我不能使用创建两者的方法并隐藏en show,因为我有其他问题。但重做我的布局后,我的面板非常小。我怎样才能让它和以前一样大小?

这是我的测试代码

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和show方法,并且还有一个调整大小的问题,但是面板是大的。我实际上解决了另一个问题,我将添加答案。

1 个答案:

答案 0 :(得分:0)

这篇文章帮我解决了我的问题(http://forums.devshed.com/python-programming-11/wxpython-refreshing-panel-panel-392700.html

添加

self.Fit()
self.GetParent().SendSizeEvent()

我的问题解决了。