wxpython多面板到swith解决方案?

时间:2012-03-08 10:37:55

标签: wxpython

changepanel0.py
  “””   四个不同的文件,名为changpanel0.py changepanel1.py changepanel2.py changepanel3.py   “”“

import wx
from changepanel1 import PanelOne
class My_App(wx.App):
    def OnInit(self):
        self.frame = My_Frame()
        self.frame.Show()
        self.SetTopWindow(self.frame)
        return True

class My_Frame(wx.Frame):
    def __init__(self):
    wx.Frame.__init__(self,None,-1,"My Frame",size = (280, 500))    
    self.panel1 = PanelOne(self) 
    self.panel1.Show()
    self.plst = []

    print self.plst

if __name__ == '__main__':
    app = My_App(False)
    app.MainLoop()

changepanel1.py

import wx
from changepanel2 import PanelTwo

class PanelOne(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent=parent)

        basicLabel = wx.StaticText(self, -1, "panel 1",pos=(80,150))
        next = wx.Button(self,-1,"Next",pos=(50,200))
        back = wx.Button(self,-1,"Back",pos=(150,200))

        self.Bind(wx.EVT_BUTTON,self.OnNext,next)
        self.Bind(wx.EVT_BUTTON,self.OnBack,back)

    def OnNext(self,event):
        self.Hide()
        self.GetParent().plst.append(self)
        tmp = PanelTwo(self.GetParent())
        tmp.Fit()
        tmp.Show()
        print self.GetParent().plst

    def OnBack(self,event):
        tmp = self.GetParent().plst.pop()
        tmp.Fit()
        tmp.Show()
        self.Destroy()

changepanel2.py

import wx
from changepanel3 import PanelThree

class PanelTwo(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent=parent)

        basicLabel = wx.StaticText(self, -1, "panel 2",pos=(80,150))
        next = wx.Button(self,-1,"Next",pos=(50,200))
        back = wx.Button(self,-1,"Back",pos=(150,200))

        self.Bind(wx.EVT_BUTTON,self.OnNext,next)
        self.Bind(wx.EVT_BUTTON,self.OnBack,back)

    def OnNext(self,event):
        self.Hide()
        self.GetParent().plst.append(self)
        tmp = PanelThree(self.GetParent())
        tmp.Fit()
        tmp.Show()
        print self.GetParent().plst

    def OnBack(self,event):
        tmp = self.GetParent().plst.pop()
        tmp.Fit()
        tmp.Show()

        print self.GetParent().plst
        self.Destroy()

changepanel3.py

import wx
class PanelThree(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent=parent)

        basicLabel = wx.StaticText(self, -1, "panel 3",pos=(80,150))
        next = wx.Button(self,-1,"Next",pos=(50,200))
        back = wx.Button(self,-1,"Back",pos=(150,200))

        self.Bind(wx.EVT_BUTTON,self.OnNext,next)
        self.Bind(wx.EVT_BUTTON,self.OnBack,back)

    def OnNext(self,event):
        self.Close()

    def OnBack(self,event):
        tmp = self.GetParent().plst.pop()
        tmp.Fit()
        tmp.Show()

        print self.GetParent().plst
        self.Destroy()

你好,我想打开多个面板,所以我使用一个列表进行维护,还有其他解决方案可以做同样的工作吗?

1 个答案:

答案 0 :(得分:0)

前段时间我写了一篇关于这个主题的tutorial,你可能会觉得有帮助。否则,请查看各种类似笔记本的控件,如Notebook或ChoiceBook,Treebook等。我wrote也是关于那些。

编辑(2012年3月19日):将不同的面板代码放入不同名称的文件中,例如panelOne.py,panelTwo.py等。然后在主应用程序中,只需导入它们:

import panelOne
import panelTwo

然后你只是实例化它们。像

这样的东西
myPanel = panelOne.PanelName(parent)

我已经提到了一种顺序切换面板的方法。