• wxpython grid


     构建Grid方法,效果如下:

    grid

     

    其它构建grid方法和grid的使用见:还可以见下载资源中的wxpython教程第5章的

    gridGeneric.py

    gridModel.py

    gridNoModel.py

     
    import wx  
    import wx.grid  
    import generictable  
          
    data = (("Bob", "Dernier"), ("Ryne", "Sandberg"),   
            ("Gary", "Matthews"), ("Leon", "Durham"),  
            ("Keith", "Moreland"), ("Ron", "Cey"),  
            ("Jody", "Davis"), ("Larry", "Bowa"),  
            ("Rick", "Sutcliffe"))  
                  
    colLabels = ("Last", "First")  
    rowLabels = ("CF", "2B", "LF", "1B", "RF", "3B", "C", "SS", "P")  
                         
    class SimpleGrid(wx.grid.Grid):  
        def __init__(self, parent):  
            wx.grid.Grid.__init__(self, parent, -1)  
            tableBase = generictable.GenericTable(data, rowLabels,   
                    colLabels)  
            self.SetTable(tableBase)                     
    class TestFrame(wx.Frame):  
        def __init__(self, parent):  
            wx.Frame.__init__(self, parent, -1, "A Grid",   
                    size=(275, 275))  
            grid = SimpleGrid(self)  
    if __name__ == '__main__':  
        app = wx.PySimpleApp()  
        frame = TestFrame(None)  
        frame.Show(True)  
        app.MainLoop()  

    grid的简单翻页demo:

    效果如下:

    导航

    源代码:

    #!/usr/bin/env <a href="http://lib.csdn.net/base/python" class='replace_word' title="Python知识库" target='_blank' style='color:#df3434; font-weight:bold;'>Python</a>  
    import wx  
    class RefactorExample(wx.Frame):  
        def __init__(self, parent, id):  
            wx.Frame.__init__(self, parent, id, 'Refactor Example',  
                    size=(340, 200))  
            panel = wx.Panel(self, -1)  
            panel.SetBackgroundColour("White")  
            self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)  
            self.createMenuBar()  
            self.createButtonBar(panel)  
            self.createTextFields(panel)  
        def menuData(self):  
            return (("&File",  
                        ("&Open", "Open in status bar", self.OnOpen),  
                        ("&Quit", "Quit", self.OnCloseWindow)),  
                    ("&Edit",  
                        ("&Copy", "Copy", self.OnCopy),  
                        ("C&ut", "Cut", self.OnCut),  
                        ("&Paste", "Paste", self.OnPaste),  
                        ("", "", ""),  
                        ("&Options...", "DisplayOptions", self.OnOptions)))  
        def createMenuBar(self):  
            menuBar = wx.MenuBar()  
            for eachMenuData in self.menuData():  
                menuLabel = eachMenuData[0]  
                menuItems = eachMenuData[1:]  
                menuBar.Append(self.createMenu(menuItems), menuLabel)  
            self.SetMenuBar(menuBar)  
        def createMenu(self, menuData):  
            menu = wx.Menu()  
            for eachLabel, eachStatus, eachHandler in menuData:  
                if not eachLabel:  
                    menu.AppendSeparator()  
                    continue  
                menuItem = menu.Append(-1, eachLabel, eachStatus)  
                self.Bind(wx.EVT_MENU, eachHandler, menuItem)  
            return menu  
        def buttonData(self):  
            return (("First", self.OnFirst),  
                    ("<< PREV", self.OnPrev),  
                    ("NEXT >>", self.OnNext),  
                    ("Last", self.OnLast))  
        def createButtonBar(self, panel, yPos = 0):  
            xPos = 0  
            for eachLabel, eachHandler in self.buttonData():  
                pos = (xPos, yPos)  
                button = self.buildOneButton(panel, eachLabel, eachHandler, pos)  
                xPos += button.GetSize().width  
        def buildOneButton(self, parent, label, handler, pos=(0,0)):  
            button = wx.Button(parent, -1, label, pos)  
            self.Bind(wx.EVT_BUTTON, handler, button)  
            return button  
        def textFieldData(self):  
            return (("First Name", (10, 50)),  
                    ("Last Name", (10, 80)))  
        def createTextFields(self, panel):  
            for eachLabel, eachPos in self.textFieldData():  
                self.createCaptionedText(panel, eachLabel, eachPos)  
        def createCaptionedText(self, panel, label, pos):  
            static = wx.StaticText(panel, wx.NewId(), label, pos)  
            static.SetBackgroundColour("White")  
            textPos = (pos[0] + 75, pos[1])  
            wx.TextCtrl(panel, wx.NewId(), "", size=(100, -1), pos=textPos)  
        # Just grouping the empty event handlers together  
        def OnPrev(self, event): pass  
        def OnNext(self, event): pass  
        def OnLast(self, event): pass  
        def OnFirst(self, event): pass  
        def OnOpen(self, event): pass  
        def OnCopy(self, event): pass  
        def OnCut(self, event): pass  
        def OnPaste(self, event): pass  
        def OnOptions(self, event): pass  
        def OnCloseWindow(self, event):  
            self.Destroy()  
    if __name__ == '__main__':  
        app = wx.PySimpleApp()  
        frame = RefactorExample(parent=None, id=-1)  
        frame.Show()  
        app.MainLoop()  
  • 相关阅读:
    Laravel报500错误
    本地部署laravel项目遇到500错误 软链接
    Class 'Maatwebsite\Excel\ExcelServiceProvider' not found
    laravel5.8报500服务器错误
    phpstudy安装redis
    如何在FastAdmin中使用Ajax发送请求?
    关于mysql处理百万级以上的数据时如何提高其查询速度的方法
    判断一个数组里面的所有键所对应的值是否是为int型
    将json字符串中含有非int型的数字字符全部改为int型
    php判断json是否是一个标准的json字符串
  • 原文地址:https://www.cnblogs.com/whwywzhj/p/6028786.html
Copyright © 2020-2023  润新知