0

在此处输入图像描述我需要创建一个 Python 框架,如附图所示。

让我知道如何完成它。

在此处输入图像描述

总共有3个块.. 1.header 2.Navigation 3.Main content..

导航块应该是多帧..每次选择一个选项时都需要更改..

它必须更像菜单导航

导入随机导入wx

#

类 TabPanel1(wx.Panel): #----------------------------------------- ----------------------------------------- def init (self, parent): """""" wx.Panel。初始化(自我,父母=父母)

    colors = ["red", "blue", "gray", "yellow", "green"]
    self.SetBackgroundColour(random.choice(colors))

panel1 = wx.Panel(self,size=(400,100))
panel1.SetBackgroundColour('#4f5049')

panel1gs = wx.GridSizer(2,2,1,2)

panel1gs.AddMany( [ (wx.StaticText(self,label='FirstLabel'),0,wx.EXPAND),
        (wx.StaticText(self,label='SecondLabel'),0,wx.EXPAND),
        (wx.StaticText(self,label='ThirdLabel'),0,wx.EXPAND),
        (wx.StaticText(self,label='FourthLabel'),0,wx.EXPAND)
        ] )

panel1.SetSizer(panel1gs)

panel2 = wx.Panel(self,size=(400,100))
panel2.SetBackgroundColour('#4f5042')

panel3 = wx.Panel(self,size=(400,100))
panel3.SetBackgroundColour('#4f5042')

    btn = wx.Button(self, label="Press Me")
    sizer = wx.BoxSizer(wx.VERTICAL)
    sizer.Add(btn, 0, wx.ALL, 5)
sizer.Add(panel1, 0, wx.ALL, 5)
sizer.Add(panel2, 0, wx.ALL, 5)
sizer.Add(panel3, 0, wx.ALL, 5)


    self.SetSizer(sizer)

类 TabPanel2(wx.Panel): #----------------------------------------- ----------------------------------------- def init (self, parent): """""" wx.Panel。初始化(自我,父母=父母)

    colors = ["red", "blue", "gray", "yellow", "green"]
    self.SetBackgroundColour(random.choice(colors))

    btn = wx.Button(self, label="Press Me")
    sizer = wx.BoxSizer(wx.VERTICAL)
    sizer.Add(btn, 0, wx.ALL, 10)

    self.SetSizer(sizer)
#

class DemoFrame(wx.Frame): """ 包含所有其他小部件的框架 """

#----------------------------------------------------------------------
def __init__(self):
    """Constructor"""        
    wx.Frame.__init__(self, None, wx.ID_ANY, 
                      "Notebook Tutorial",
                      size=(800,600)
                      )
    panel = wx.Panel(self)

    notebook = wx.Notebook(panel)
    tabOne = TabPanel1(notebook)
    notebook.AddPage(tabOne, "Tab 1")

    tabTwo = TabPanel2(notebook)
    notebook.AddPage(tabTwo, "Tab 2")

    sizer = wx.BoxSizer(wx.VERTICAL)
    sizer.Add(notebook, 1, wx.ALL|wx.EXPAND, 5)
    panel.SetSizer(sizer)
    self.Layout()

    self.Show()

-------------------------------------------------- --------------------

如果name == " main ": app = wx.App(False) frame = DemoFrame() app.MainLoop()

最新更改 Newcode.py

import random
import wx


########################################################################
class PanelTextCombo(wx.Panel):
     def __init__(self,parent):
    wx.Panel.__init__(self,parent=parent,size=(400,100))

    self.SetBackgroundColour('blue')

    panel1gs = wx.GridSizer(2,2,1,2)

    panel1gs.AddMany( [ (wx.StaticText(panel1,label='FirstLabel'),0),
            (wx.StaticText(panel1,label='SecondLabel'),0),
            (wx.StaticText(panel1,label='ThirdLabel'),0),
            (wx.StaticText(panel1,label='FourthLabel'),0)
            ] )



    panel1.SetSizer(panel1gs)

class TabPanel1(wx.Panel):
    #----------------------------------------------------------------------
    def __init__(self, parent):
        """"""
        wx.Panel.__init__(self, parent=parent)

        colors = ["red", "blue", "gray", "yellow", "green"]
        #self.SetBackgroundColour(random.choice(colors))
    self.SetBackgroundColour('RED')

    #panel1 = wx.Panel(self,size=(400,100))
    #panel1.SetBackgroundColour('blue')

    #panel1gs = wx.GridSizer(2,2,1,2)

    #panel1gs.AddMany( [ (wx.StaticText(panel1,label='FirstLabel'),0),
    #       (wx.StaticText(panel1,label='SecondLabel'),0),
    #       (wx.StaticText(panel1,label='ThirdLabel'),0),
    #       (wx.StaticText(panel1,label='FourthLabel'),0)
    #       ] )

    #panel1.SetSizer(panel1gs)
    panel1 = PanelTextCombo(TabPanel1)
    #panel2 = wx.Panel(self,size=(400,100))
    #panel2.SetBackgroundColour('green')

    #panel3 = wx.Panel(self,size=(400,100))
    #panel3.SetBackgroundColour('#4f5042')

        btn = wx.Button(self, label="Press Me")
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(btn, 0, wx.ALL, 5)
    sizer.Add(panel1, 0, wx.ALL, 5)
    #sizer.Add(panel2, 0, wx.ALL, 5)
    #sizer.Add(panel3, 0, wx.ALL, 5)


        self.SetSizer(sizer)

class TabPanel2(wx.Panel):
    #----------------------------------------------------------------------
    def __init__(self, parent):
        """"""
        wx.Panel.__init__(self, parent=parent)

        colors = ["red", "blue", "gray", "yellow", "green"]
        self.SetBackgroundColour(random.choice(colors))

        btn = wx.Button(self, label="Press Me")
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(btn, 0, wx.ALL, 10)

        self.SetSizer(sizer)

########################################################################
class DemoFrame(wx.Frame):
    """
    Frame that holds all other widgets
    """

    #----------------------------------------------------------------------
    def __init__(self):
        """Constructor"""        
        wx.Frame.__init__(self, None, wx.ID_ANY, 
                          "Notebook Tutorial",
                          size=(800,600)
                          )
        panel = wx.Panel(self)

        notebook = wx.Notebook(panel)
        tabOne = TabPanel1(notebook)
        notebook.AddPage(tabOne, "Tab 1")

        tabTwo = TabPanel2(notebook)
        notebook.AddPage(tabTwo, "Tab 2")

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(notebook, 1, wx.ALL|wx.EXPAND, 5)
        panel.SetSizer(sizer)
        self.Layout()

        self.Show()

#----------------------------------------------------------------------
if __name__ == "__main__":
    app = wx.App(False)
    frame = DemoFrame()
    app.MainLoop()
4

1 回答 1

1

使用 wx.StaticText 作为顶部的标签,然后使用 wx.Notebook(或其他“书”小部件之一)作为其余部分。请参阅以下教程:

于 2012-09-21T13:21:00.953 回答