zoukankan      html  css  js  c++  java
  • Notebook 分页

    Notebook模块可以实现分页功能,在分割展示大量信息时有用

    主要流程:
    1.在Frame框架中新建一个Notebook

    notebook=wx.Notebook(self)

    2.利用Notebook类中的AddPage()方法,为这个实例添加分页,分页是Panel(也有的用windows)

    notebook.AddPage(PanelPage1(notebook),"Editor")
    class PanelPage1(wx.Panel):
        def __init__(self,parent):
            wx.Panel.__init__(self,parent=parent)
            text=wx.TextCtrl(self,style=wx.TE_MULTILINE,size=(250,150))

    其中还要说一下wxpython的窗口继承

    parent表示这个控件显示在parent之上,parent里面包含了所有的孩子控件

    如在class NoteFrame中

    notebook=wx.Notebook(self)

    表示notebook控件是在当前Frame中的,self就是class NoteFrame

    notebook.AddPage(PanelPage1(notebook),"Editor")
    class PanelPage1(wx.Panel):
        def __init__(self,parent):

    PanelPage1的构造函数只有parent一个输入,所以PanelPage1(notebook),PanelPage1的父亲空间就是notebook

    整个空间的继承结构就是NoteFrame=>notebook=>PanelPage1/PanelPage2

    完整代码

    import wx
    
    # class MyDialog(wx.Dialog):
    #     def __init__(self,parent,title):
    #         wx.Dialog.__init__(self,parent=parent,title=title,size=(250,150))
    #         panel=wx.Panel(self,-1)
    #         self.button=wx.Button(panel,wx.ID_OK,label="ok",size=(50,20),pos=(75,50))
    
    
    class NoteFrame(wx.Frame):
        def __init__(self,parent,title):
            wx.Frame.__init__(self,parent=parent,title=title,size=(250,150))
            self.InitUI()
    
        def InitUI(self):
            notebook=wx.Notebook(self)
            notebook.AddPage(PanelPage1(notebook),"Editor")
            notebook.AddPage(PanelPage2(notebook),"Text")
    
            # 将窗口显示在屏幕中间
            self.Centre()
    
    
    # 第一个窗口分页
    class PanelPage1(wx.Panel):
        def __init__(self,parent):
            wx.Panel.__init__(self,parent=parent)
            text=wx.TextCtrl(self,style=wx.TE_MULTILINE,size=(250,150))
    
    # 第二个窗口分页
    class PanelPage2(wx.Panel):
        def __init__(self,parent):
            wx.Panel.__init__(self,parent=parent)
            text1=wx.StaticText(self,label="Window (Panel) 2",)
    
    
    if __name__=="__main__":
        app=wx.App()
        frame=NoteFrame(None,"Notebook demo")
        frame.Show(True)
        app.MainLoop()

     

  • 相关阅读:
    单例模式的八种写法
    反射
    工厂模式
    Java内存分配、管理小结
    Java 反射(二)
    Java反射
    servlet的web-xml配置详解
    substr和substring的区别
    C/C++中extern关键字详解
    lua总则
  • 原文地址:https://www.cnblogs.com/wangtianning1223/p/14118696.html
Copyright © 2011-2022 走看看