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

Dear Monks, I am experimenting with using Tk, but it now gives me the strange error "no event type or button # or keysym...." It seems te refer to the BrowseEntry but I checked with my book "Mastering Perl/Tk" and it looks good. Thanks in advance for any help.
#!/usr/bin/perl use Tk; use strict; use warnings; require Tk::BrowseEntry; my $mw=MainWindow->new; my $f=$mw->Frame(-borderwidth=>2)->pack(-side=>'top', -fill=>'x'); my (@packwith) =(); my $numwidgets=4; for(my $i=0;$i<$numwidgets;$i++) { my $be = $f->BrowseEntry(-label => "Widget $i", -choices => ["left +", "right", "top", "bottom"], -variable => \$packwith[$i], -browsecmd => \&repack) - +> pack( -ipady=>20); } my $b=$f->Button(-text =>"repack", -command=> \&repack)->pack(-side => + "bottom"); my $tl=$mw->Toplevel(-title=>"output"); for (my $i=0;$i<$numwidgets;$i++) { my $b=$tl->Button(-text=> "Button $i")->pack(-side => $packwith[$i +]); } MainLoop; sub repack { my @slaves = $tl->packSlaves; my $j=0; foreach (@slaves) { $_->packForget; $_->pack(-text => "Button ".$j, -side=>\$packwith[$j++]); } }

Replies are listed 'Best First'.
Re: Strange Perl/Tk error
by lamprecht (Friar) on Mar 27, 2010 at 12:59 UTC
    Hi,

    Tk-804.028_502 solves your problem.

    -text is not a valid option to pack btw.


    Cheers, Chris
      Hi Chris, Thanks for your help ! I downloaded and installed the Tk-804.028_502 development release and it immediately solved my problem. Thanks !!!!! Kind regards, Ivo.
        And also my thanks to all others who replied. This site is great !
      Thanks for this post. I have a legacy Perl/Tk application that a client needs ported to Solaris 11 x86-64. I have perl 5.6.1 and Tk800.024, and I am getting this post's subject error message.

      I am not able to build (or probably use) Tk-804.028_502 as recommended, so I was wondering what you think about the viability of these alternatives:

      a) Is the cause of this issue relegated to one or a few C files which can be merged into Tk800.024 and then rebuilt, or

      b) Is is possible to use a SREZIC-Patch style patch? Thanks!

        The Tk Bug Tracker on SourceForge provided a very detailed post which allowed me to create a workaround for the ancient copy of Perk/Tk I have to use. Basically, X.Org added a new event, which pushed protocol constant LASTEvent from 35 to 36, and assumptions were made as to that value always being 35.

        The changes I made were as follows (colored red)to the named source files in the Tk800.024 source distro.

        ./pTk/mTk/xlib/X11/X.h
        #define MappingNotify 34
        #define GenericEvent 35
        #define LASTEvent 36 /* must be bigger than any event # */

        ./pTk/tkBind.c
        ./pTk/mTk/generic/tkBind.c
        static int flagArrayTK_LASTEVENT = {
        ...
        /* MappingNotify */ 0,
        /*CN Not used */ 0,
        ...
        };

        ./pTk/tkEvent.c
        ./pTk/mTk/generic/tkEvent.c
        static unsigned long eventMasksTK_LASTEVENT = {
        ...
        0, /* Mapping Notify */
        0, /*CN X.Org added 'GenericEvent' */
        ...
        };

Re: Strange Perl/Tk error
by moritz (Cardinal) on Mar 27, 2010 at 09:30 UTC
    Oddly enough, when I run your program I get no error message at all. Neither do I get a window, it just uses up all CPU and runs forever.

    Are you sure this is actually the program that gives you an error? (I have perl 5.10 and Tk 804.028 installed here)

    Perl 6 - links to (nearly) everything that is Perl 6.
      Sorry, for loop missed $ I updated it above. I think maybe my Tk installation is broken as I still get the error. Thanks for your reply.
Re: Strange Perl/Tk error
by Khen1950fx (Canon) on Mar 27, 2010 at 11:03 UTC
    The problem was on line 26. I changed ->pack(-side => packwith... to top:
    #!/usr/bin/perl use strict; use warnings; use Tk; require Tk::BrowseEntry; my $mw=MainWindow->new; my $f=$mw->Frame(-borderwidth=>2)->pack(-side=>'top', -fill=>'x'); my (@packwith) =(); my $numwidgets=4; for(my $i=0;$i<$numwidgets;$i++) { my $be = $f->BrowseEntry(-label => "Widget $i", -choices => ["left +", "right", "top", "bottom"], -variable => \$packwith[$i], -browsecmd => \&repack) - +> pack( -ipady=>20); } my $b=$f->Button(-text =>"repack", -command=> \&repack)->pack(-side => + "bottom"); my $tl=$mw->Toplevel(-title=>"output"); for (my $i=0;$i<$numwidgets;$i++) { my $b=$tl->Button(-text=> "Button $i")->pack(-side => 'top'); } MainLoop; sub repack { my @slaves = $tl->packSlaves; my $j=0; foreach (@slaves) { $_->packForget; $_->pack(-text => "Button ".$j, -side=>\$packwith[$j++]); } }
Re: Strange Perl/Tk error
by Khen1950fx (Canon) on Mar 27, 2010 at 10:27 UTC
    I tested it as is and got the same result as moritz. However, if you add strictures, you'll get a ton of error warnings. Always use strict and use warnings.
      i fixed the errors and warnings in the updated code above, sorry for that.
      Thanks for testing. I removed Tk and then reinstalled Tk using cpan but it had no effect. Does anyone have an idea how to fix Tk ? Im using Kubuntu 9.10.