Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello Perl Monks - who always prove to be smarter than me!! I have a perl script with a Tcl::Tk GUI and I can't get the listbox to work properly. It displays in the GUI but upon selection it throws the following error ,"Tcl error 'wrong # args: should be ".lb28 get firstIndex ?lastIndex?" at...". I've been googling for days and the reading everything I can online but I don't know what dumb mistake I'm making. Any help is greatly appreciated. Here's my code

#################################### #testing new my @cursors = qw/ 12 24 48 96/; my $lb = $mw->Listbox(-selectmode => 'single', ); $lb->pack(-side => 'left', -fill => 'both'); $lb->insert('end', sort @cursors); $lb->bind('<Button-1>', sub { $mw->configure(-background => $lb->get($lb->curselection)); + }); $lb->grid( -row => 10, -column => 2, -columnspan => 1);

Thanks again for the help.

Replies are listed 'Best First'.
Re: Tcl::Tk listbox error
by GrandFather (Saint) on Feb 09, 2017 at 07:23 UTC

    It would help if you provided enough code to actually run and demonstrate the problem. Given code demonstrating the problem it would also help to show the full error message - at... doesn't give much context for the error!

    I notice that cpan testers don't show many passing combinations of OS and Perl version for the module (see http://matrix.cpantesters.org/?dist=Tcl-Tk+1.04). You may be better working with an alternative version of Tk? Tk is fairly commonly available and does better with the testers (http://matrix.cpantesters.org/?dist=Tk%20804.033).

    Premature optimization is the root of all job security

      I was interested to see how much I needed to change the supplied code to get something running with Tk

      use strict; use warnings; use Tk; my @cursors = qw/ 12 24 48 96/; my $mw = new MainWindow; my $lb = $mw->Listbox(-selectmode => 'single', ); $lb->pack(-side => 'left', -fill => 'both'); $lb->insert('end', sort @cursors); $lb->bind('<Button-1>', sub { $mw->configure(-background => $lb->get($lb->curselection)); + }); $lb->grid( -row => 10, -column => 2, -columnspan => 1); MainLoop();

      Turns out, two lines - initialise $mw and call MainLoop(). The code executes without error and shows a main window containing a list.

      Premature optimization is the root of all job security

      I notice that cpan testers don't show many passing combinations of OS and Perl version for the module ...

      Yup, an actual tcl installation is a prerequisite, and most cpan-testers dont have tcl installed, thats how it goes

Re: Tcl::Tk listbox error
by Anonymous Monk on Feb 09, 2017 at 07:36 UTC

    Hi

    but upon selection it throws the following error ,"Tcl error 'wrong # args: should be ".lb28 get firstIndex ?lastIndex?" at...". I've been googling for days and the reading everything I can online but I don't know what dumb mistake I'm making. $lb->get($lb->curselection));

    What is this "everything"?