wx.listctrl and size
Jeffrey Barish
jeff_barish at earthlink.net
Sat Dec 30 08:27:28 PST 2006
Laurent FRANCOIS wrote:
> Here a very little and simple code for a
> wx.listctrl.
> But as you will maybe see the control list doesn't use
> all the panel size. There is a scroll bar
Mostly, you need to use a sizer. Here's one solution that works. Read the
wxPython style guide:
http://wiki.wxpython.org/index.cgi/wxPython_Style_Guide
especially the section on wx.ID_ANY. Naming your class ListCtrl is asking
for confusion with wx.ListCtrl. You need to insert a string item before
you try to set it. Setting an instance variable outside the instance
(e.g., self.panel.list) is bad form unless there is a good reason for doing
so. In your program, it isn't even necessary to use instance variables.
Also read the Python style guide:
http://www.python.org/doc/essays/styleguide.html
especially the section on where to put spaces.
##------------
# -*- coding: latin1 -*-
import wx
class MyListCtrl(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "Construction d'une liste",
size=(600, 300))
panel = wx.Panel(self, wx.ID_ANY)
##--Creation de la liste
list = wx.ListCtrl(panel, wx.ID_ANY, style=wx.LC_REPORT)
##--Creation des colonnes de la liste
list.InsertColumn(0, 'column 1', format=wx.LIST_FORMAT_CENTER,
width=400)
list.InsertColumn(1, 'column 2', format=wx.LIST_FORMAT_RIGHT,
width=200)
##--peuplement des cellules
index = list.InsertStringItem(0, 'cell A1')
list.SetStringItem(index, 1, 'cell A2')
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(list, 1, wx.EXPAND)
panel.SetSizer(sizer)
##--Le main Loop
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = MyListCtrl()
frame.Show(True)
app.MainLoop()
##----------------
--
Jeffrey Barish
More information about the wxpython-users
mailing list