import wx class MainFrame(wx.MDIParentFrame): def __init__(self, parent, title): wx.MDIParentFrame.__init__(self, parent, -1, title) # Create a menu bar menubar = wx.MenuBar() fileMenu = wx.Menu() newChildItem = fileMenu.Append(wx.ID_ANY, "&New Child Window") exitItem = fileMenu.Append(wx.ID_EXIT, "E&xit") menubar.Append(fileMenu, "&File") self.SetMenuBar(menubar) # Bind events self.Bind(wx.EVT_MENU, self.OnNewChild, newChildItem) self.Bind(wx.EVT_MENU, self.OnExit, exitItem) def OnNewChild(self, event): childFrame = ChildFrame(self, "Child Window") childFrame.Show() def OnExit(self, event): self.Close() class ChildFrame(wx.MDIChildFrame): def __init__(self, parent, title): wx.MDIChildFrame.__init__(self, parent, -1, title) if __name__ == "__main__": app = wx.App() frame = MainFrame(None, "MDI Example") frame.Show() app.MainLoop()
import wx class TabbedFrame(wx.Frame): def __init__(self, parent, id, title): wx.Frame.__init__(self, parent, id, title, size=(800, 600)) self.notebook = wx.Notebook(self, -1, style=wx.NB_TOP) # 创建第一个标签页 self.create_tab("Tab 1") # 创建第二个标签页 self.create_tab("Tab 2") sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(self.notebook, 1, wx.EXPAND | wx.ALL, 5) self.SetSizer(sizer) def create_tab(self, title): panel = wx.Panel(self.notebook) text = wx.StaticText(panel, -1, f"This is {title}") sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(text, 1, wx.EXPAND | wx.ALL, 10) panel.SetSizer(sizer) self.notebook.AddPage(panel, title) app = wx.App(False) frame = TabbedFrame(None, -1, "Tabbed Frame") frame.Show() app.MainLoop()
import wx import wx.aui class MyFrame(wx.Frame): def __init__(self, parent, title): wx.Frame.__init__(self, parent, title=title, size=(800, 600)) self.notebook = wx.aui.AuiNotebook(self) self.notebook.SetArtProvider(wx.aui.AuiSimpleTabArt()) # Use a simpler tab art # Create some panels for the tabs panel1 = wx.Panel(self.notebook) panel2 = wx.Panel(self.notebook) # Add the panels to the notebook with close buttons self.notebook.AddPage(panel1, "Tab 1", True) self.notebook.AddPage(panel2, "Tab 2", True) # Bind the close button event self.notebook.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self.on_page_close) self.Show(True) def on_page_close(self, event): page = event.GetSelection() self.notebook.DeletePage(page) if __name__ == '__main__': app = wx.App() frame = MyFrame(None, "MDI-like Tabbed Interface") app.MainLoop()
标签:__,title,python,create,notebook,init,wxpython,self,wx From: https://www.cnblogs.com/geovindu/p/18591398