为MDIChildFram创建笔记本选项卡

2021-03-02 15:17:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我希望能够使用wxflatnotebook或类似工具在MDIChildFrame之间切换。我已经包括我的代码和一个图像的例子,我正在寻找。我要复制的标签是(GPBUSD)&;(eursud)。到目前为止,我没有任何运气,所以任何信息将非常感谢。在

import wx
import wx.lib.agw.aui as aui

class MDIFrame(wx.MDIParentFrame):
    def __init__(self):
        wx.MDIParentFrame.__init__(self, None, -1, "MDI Parent", size =(1350, 720))
        menu = wx.Menu()
        menu.append(5000, "&New Window")
        menu.Append(5001, "&Exit")
        menubar = wx.MenuBar()
        menubar.Append(menu, "&File")
        self.SetMenuBar(menubar)
        self.Bind(wx.EVT_MENU, self.OnNewWindow, id=5000)
        self.Bind(wx.EVT_MENU, self.OnExit, id=5001)
        self.mgr = aui.AuiManager(self, aui.AUI_MGR_DEFAULT
                                       |aui.AUI_MGR_TRANSPARENT_DRAG
                                       |aui.AUI_MGR_ALLOW_ACTIVE_PANE                                     
                                       |aui.AUI_MGR_TRANSPARENT_HINT)                      
        self.inputPanel = wx.Panel(self, -1)
        self.BuildPain()

    def BuildPain(self):                             
        self.mgr.AddPane(self.GetClientWindow(),
                         aui.AuiPaneInfo().Name("book").Caption("Notebook").
                         CenterPane().CaptionVisible(True).Dockable(True).Floatable(False).
                         BestSize((300,300)).CloseButton(False).MaximizeButton(True)
                         )    
        self.mgr.AddPane(self.inputPanel,
                        aui.AuiPaneInfo().Name("input").Caption("Input panel").
                         CaptionVisible(True).Left().Dockable(True).Floatable(True).
                         BestSize((300,300)).CloseButton(False).MaximizeButton(True)
                         )
        self.mgr.Update()

    def OnExit(self, evt):
        self.Close(True)

    def OnNewWindow(self, evt):
        win = wx.MDIChildFrame(self, -1, "Child Window")
        win.Show(True)

if __name__ == "__main__":
    app = wx.App(0)
    frame = MDIFrame()
    frame.CenterOnScreen()
    frame.Show()
    app.MainLoop()

Example Image http://imageshack.us/a/img534/280/mdip.png

1条回答
网友
1楼 ·

也许你可以试试AuiMDIParentFrame,AuiMDIChildFrame是tab inParentFrame。这里代码是:

#!/usr/bin/env python
#-*- encoding: gb18030 -*-
import wx
import wx.aui

#                                   

class ParentFrame(wx.aui.AuiMDIParentFrame):
    def __init__(self,parent):
        wx.aui.AuiMDIParentFrame.__init__(self, parent,-1,
                                          title="AuiMDIParentFrame",
                                          size=(640,480),
                                          style=wx.DEFAULT_FRAME_STYLE)
        self.count = 0
        # tell FrameManager to manage this frame

        #creat menu
        mb = self.MakeMenuBar()
        self.SetMenuBar(mb)

        #creat statubar
        self.statusbar = self.CreateStatusBar(2, wx.ST_SIZEGRIP)
        self.statusbar.SetStatusWidths([-2, -3])
        self.statusbar.SetStatusText("Ready", 0)
        self.statusbar.SetStatusText("Welcome To wxPython!", 1)

        #create toolbar


    def MakeMenuBar(self):
        mb = wx.MenuBar()
        menu = wx.Menu()
        item = menu.Append(-1, "New child window\tCtrl-N")
        self.Bind(wx.EVT_MENU, self.OnNewChild, item)
        item = menu.Append(-1, "Close parent")
        self.Bind(wx.EVT_MENU, self.OnDoClose, item)
        mb.Append(menu, "&File")
        return mb

    def OnNewChild(self, evt):
        self.count += 1
        try:
            child = ChildFrame(self, self.count)
        except Exception,data:
            print data
        child.Show()

    def OnDoClose(self, evt):
        self.Close()


#                                   

class ChildFrame(wx.aui.AuiMDIChildFrame):
    def __init__(self, parent, count):
        wx.aui.AuiMDIChildFrame.__init__(self, parent, -1,
                                         title="Child: %d" % count)
        mb = parent.MakeMenuBar()
        menu = wx.Menu()
        item = menu.Append(-1, "This is child %d's menu" % count)
        mb.Append(menu, "&Child")
        self.SetMenuBar(mb)

        p = wx.Panel(self)
        wx.StaticText(p, -1, "This is child %d" % count, (10,10))
        p.SetBackgroundColour('light blue')

        sizer = wx.BoxSizer()
        sizer.Add(p, 1, wx.EXPAND)
        self.SetSizer(sizer)

        wx.CallAfter(self.Layout)


if __name__ == '__main__':
    App = wx.App()
    frame = ParentFrame(None)
    App.SetTopWindow(frame)
    frame.Show()
    App.MainLoop()

相关问题