in reply to Tk (Tcl::Tk) programmatically monitor change in Listbox
#! /usr/bin/perl use strict; use warnings; use Tk; my $mw = 'MainWindow'->new; my $lbox = $mw->Listbox->pack; my @list = qw( a b c d e f ); $lbox->insert(end => @list); $lbox->selectionSet(1); my @selection; $lbox->repeat(100, sub { my @current = $lbox->curselection; warn "Listbox changed!\n" if "@selection" ne "@current"; @selection = @current; }); my $f = $mw->Frame->pack; $f->Button(-text => 'Add', -command => sub { $lbox->selectionSet(2) })->pack(-side => +'left'); $f->Button(-text => 'Clear', -command => sub { $lbox->selectionClear(0, 'end') })->pack; MainLoop();
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Tk programmatically monitor change in Listbox
by IB2017 (Pilgrim) on Jan 06, 2020 at 09:44 UTC |