wxpython 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()  
时间: 2024-10-18 02:38:34

wxpython grid的相关文章

wxPython控件学习之wx.grid.Grid 表格控件

wxPython控件学习之wx.grid.Grid (包括对GridCellEditor和GridCelRender的扩展,以支持更多的grid cell 样式, 以GridCellColorEditor为例) wx.Grid 及其相关的类是用来显示和编辑类表格样式的数据.该控件为显示,编辑数据源提及交互供了丰富的特征. wx.GridTableBase类控制要显示的实际数据.可以call CreateGrid()产生一个该类的实例对象. wx.GridCellRenderer 基类,负责对单元

wxPython应用心得

在遍找可以拖拽设计wxPython窗体没找到如意的后,只有把wxPython学一学了,一个简单的项目完成后,总结一些小心得: StaticText控件改变里面的内容用SelLabel方法 整体布局用GridBagSizer,因为你只要告诉sizer你把某个控件插在哪一行哪一列,同时告知横跨多少行多少列即可 bag=wx.GridBagSizer(5,5)#生成行列间距为5的布局控件 bag.Add(btn1,pos=(0,0))#第1行第一列加入一个按钮 bag.Add(label1,pos=(

[译] 开始使用 wxPython [Getting started with wxPython]

原文:http://wiki.wxpython.org/Getting%20Started 1. 第一个应用程序:Hello World 按照“国际惯例”,我们先写一个“Hello World”的应用程序,下面是代码: 1 #!/usr/bin/env python 2 import wx 3 4 app = wx.App(False) # Create a new app, don't redirect stdout/stderr to a window. 5 frame = wx.Frame

wxPython布局管理器(sizer)学习(1)

个人认为学习GUI程序开发,最重要的两个基础点就是:事件处理和界面布局.事件处理能够让你在界面上的控件被鼠标.按键等触发的时候做出合适的响应,比如点击“保存”按钮之后弹出标准的文件保存对话框.另外一件重要的就是界面的布局,之所以要有GUI程序,就是为了有良好的用户体验,如果一个软件界面布局乱七八糟的话,肯定是不合适的.至于按钮.文本框.静态文本这些组件,不过是通过相应的类产生实例并用Add之类的方法添加到面板上而已. wxPython的sizer是用于自动布局一组窗口(之前提到过GUI程序开发中

wxpython 中的所有控件及高级应用

转自http://xoomer.virgilio.it/infinity77/Phoenix/lib.agw.html,,,哈哈终于找到了这块的内容,书上基本没有讲解 This is the Advanced Generic Widgets package (AGW). It provides many custom-drawn wxPython controls: some of them can be used as a replacement of the platform native

wxPython Bind key events

In this post, I’ll detail how to catch specific key presses and why this can be useful. This is another in my series of “requested” tutorials. There really isn’t much to catching key presses, but it can be a little confusing when one widget behaves s

Python爬糗百热门20条并邮件分发+wxPython简易GUI+py2app转成可运行文件

学了一阵子Python,拿来做个什么有意思的东西呢?爬糗百好了.爬到的内容,邮件分发出去. 然后又啃了两天的wxpython,做了个简易的邮件管理界面,能够在这里添加或者删除邮件,而且一键爬虫发送. 最后,索性封装成APP吧.又试了一把py2app.简单好用. 因为是让用户自行加入和删除邮箱.所以程序一定要兼顾到各种情况:比方输入的邮箱格式不合法.输入的邮箱里包括中文字符,分隔符不正确,删除了所有邮箱然后又要发邮件等问题. 首先是QiuBai.py:爬虫,正则匹配我们想要的内容.然后将内容稍作处

Python爬糗百热门20条并邮件分发+wxPython简易GUI+py2app转成可执行文件

学了一阵子Python,拿来做个什么有意思的东西呢?爬糗百好了,爬到的内容,邮件分发出去. 然后又啃了两天的wxpython,做了个简易的邮件管理界面,可以在这里增加或者删除邮件,并且一键爬虫发送. 最后,索性封装成APP吧,又试了一把py2app,简单好用. 首先是QiuBai.py:爬虫,正则匹配我们想要的内容,然后将内容稍作处理返回. #!/usr/bin/env python # -*- coding: utf-8 -*- import re import urllib2 __autho

wxPython实例代码(购物车)

wxPython是一个流行的跨平台GUI工具包.用这个就可以给程序做窗口界面了.官方网站:www.wxpython.org我这也没好好学,就整了个小项目的例子.把代码完整贴下面了,下次做界面的时候可以参考这改改. 文档结构 主要就是几个py文件.resources文件夹里是放资源原件的,也就两张图片 Cart │ app_main.py │ ├─conf │ settings.py │ __init__.py │ ├─resources │ bats.ico │ dragon.jpg │ └─u