import wx ######################################################################## class MyForm(wx.Frame): #---------------------------------------------------------------------- def __init__(self): wx.Frame.__init__(self, None, wx.ID_ANY, "List Control Tutorial") # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self.index = 0 self.list_ctrl = wx.ListCtrl(panel, size=(-1,100), style=wx.LC_REPORT |wx.BORDER_SUNKEN ) self.list_ctrl.InsertColumn(0, 'Subject') self.list_ctrl.InsertColumn(1, 'Due') self.list_ctrl.InsertColumn(2, 'Location', width=125) btn = wx.Button(panel, label="Add Line") btn.Bind(wx.EVT_BUTTON, self.add_line) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(self.list_ctrl, 0, wx.ALL|wx.EXPAND, 5) sizer.Add(btn, 0, wx.ALL|wx.CENTER, 5) panel.SetSizer(sizer) #---------------------------------------------------------------------- def add_line(self, event): line = "Line %s" % self.index self.list_ctrl.InsertStringItem(self.index, line) self.list_ctrl.SetStringItem(self.index, 1, "01/19/2010") self.list_ctrl.SetStringItem(self.index, 2, "USA") self.index += 1 #---------------------------------------------------------------------- # Run the program if __name__ == "__main__": app = wx.App(False) frame = MyForm() frame.Show() app.MainLoop() #### # wxPerl list control test 7 3 2013. Based on Tutorial 8 # Taken from: http://wxperl.sourceforge.net/tutorial/tutorial4.html # and http://www.blog.pythonlibrary.org/2011/01/04/wxpython-wx-listctrl-tips-and-tricks/ use strict; use warnings; use warnings qw< FATAL utf8 >; use Wx; use Encode; use 5.014; use utf8; use autodie; use Carp; use Carp qw {cluck}; use Carp::Always; use Win32::Console; use English '-no_match_vars'; package MyApp; use base 'Wx::App'; use Wx qw{ wxLC_REPORT wxBORDER_SUNKEN wxVERTICAL wxALL wxEXPAND wxCENTER}; sub OnInit { my $frame = MyForm->new; $frame->Show( 1 ); } # end package MyApp; package MyForm; use base 'Wx::Frame'; use Wx qw{ wxLC_REPORT wxBORDER_SUNKEN wxVERTICAL wxALL wxEXPAND wxCENTER}; # import the event registration function use Wx::Event qw(EVT_BUTTON); our ($idx, $list_ctrl); sub new { my $ref = shift; my $self = $ref->SUPER::new( undef, # parent window -1, # ID -1 means any 'List Control Tutorial', # title [-1, -1], # default position [400, 300], # size ); # Add a panel so it looks correct on all platforms my $panel = Wx::Panel->new( $self, # parent window -1, # ID ); $idx = 0; $list_ctrl = Wx::ListCtrl-> new ($panel, -1, # ID 'Report', # label [20,30], # position [-1,100], # size &Wx::wxLC_REPORT | &Wx::wxBORDER_SUNKEN, # window style ); $list_ctrl->InsertColumn( 0, 'Subject' ); $list_ctrl->InsertColumn( 0, 'Due' ); $list_ctrl->InsertColumn( 0, 'Location' ); my $btn = Wx::Button->new( $panel, # parent window -1, # ID 'Add Line', # label [-1, -1], # default position [-1, -1], # default size ); EVT_BUTTON( $self, $btn, \&add_line ); my $sizer = Wx::BoxSizer->new(&Wx::wxVERTICAL); $sizer->Add($list_ctrl, 0, &Wx::wxALL| &Wx::wxEXPAND, 5); $sizer->Add($btn, 0, &Wx::wxALL | &Wx::wxCENTER, 5); $panel->SetSizer($sizer); } # end sub new sub add_line { # my $event; my ( $self, $event ) = @_; my $line = "Line $idx"; $list_ctrl->InsertStringItem($idx, $line); $list_ctrl->SetStringItem($idx, 1, '01/19/2010'); $list_ctrl->InsertStringItem($idx, 2, 'USA'); $idx += 1; } # end sub add_line 1; # end package MyForm; package main; my $app = MyApp->new; $app->MainLoop; 1; #### variable is not of type Wx::Point at Wx List Control test PerlO.pl line 52 MyForm::new('MyForm') called at Wx List Control test PerlO.pl line 25 MyApp::OnInit('MyApp=HASH(0x2407e64)') called at F:/Win7programs/Dwimperl/perl/site/lib/Wx/App.pm line 36 eval {...} called at F:/Win7programs/Dwimperl/perl/site/lib/Wx/App.pm line 36 Wx::App::new('MyApp') called at F:/Win7programs/Dwimperl/perl/site/lib/Wx/App.pm line 36 Wx::App::new('MyApp') called at Wx List Control test PerlO.pl line 88 #### $list_ctrl = Wx::ListCtrl-> new ($panel, -1, # ID 'Report', # label [20,30], # position [-1,100], # size &Wx::wxLC_REPORT | &Wx::wxBORDER_SUNKEN, # window style );