13.07.2015 Views

The wxPython tutorial

The wxPython tutorial

The wxPython tutorial

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Advanced widgetshttp://www.zetcode.com/wxpython/advanced/Figure: AutoWidth exampleIn the following example we will show, how we can create sortable columns.If we click on the column header, the corresponding rows in a column aresorted.#!/usr/bin/python# sorted.pyimport wximport sysfrom wx.lib.mixins.listctrl import ColumnSorterMixinactresses = {1 : ('jessica alba', 'pomona', '1981'),2 : ('sigourney weaver', 'new york', '1949'),3 : ('angelina jolie', 'los angeles', '1975'),4 : ('natalie portman', 'jerusalem', '1981'),5 : ('rachel weiss', 'london', '1971'),6 : ('scarlett johansson', 'new york', '1984')}class SortedListCtrl(wx.ListCtrl, ColumnSorterMixin):def __init__(self, parent):wx.ListCtrl.__init__(self, parent, -1, style=wx.LC_REPORT)ColumnSorterMixin.__init__(self, len(actresses))self.itemDataMap = actressesdef GetListCtrl(self):return selfclass Actresses(wx.Frame):def __init__(self, parent, id, title):wx.Frame.__init__(self, parent, id, title, size=(380, 230))hbox = wx.BoxSizer(wx.HORIZONTAL)panel = wx.Panel(self, -1)self.list = SortedListCtrl(panel)self.list.InsertColumn(0, 'name', width=140)self.list.InsertColumn(1, 'place', width=130)self.list.InsertColumn(2, 'year', wx.LIST_FORMAT_RIGHT, 90)items = actresses.items()for key, data in items:14 de 21 27/04/2008 1:05

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!