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

Hello!

I finally got around to attempting to learn how to use perl/tk.

I keep getting this error:

no event type or button # or keysym at /usr/lib64/perl5/vendor_perl/5. +8.8/x86_64-linux-thread-multi/Tk/Widget.pm line 1105. at ./ThreadFeed.pl line 16

I started out with the tutorial right here in the temple at http://perlmonks.org/?node_id=181977 and running the "sigeval.pl" I get that error at line 58 of sigeval.pl

I tried running some example code from another tutorial I found on google which produced that error on this line (line 16 of ThreadFeed.pl): my $txt = $textarea -> Text(-width=>40, -height=>10);

I recently rebuilt perl with the "ithreads" support and I also rebuilt the TK module and a few others just in case.

I've searched everywhere and found a couple mentions of this problem on google but no solutions/explanations. Can anybody shed some light on this?

Thanks!

Here is the "ThreadFeed.pl" file, It is just some example code from the tutorial I found, un-altered.

#!/usr/bin/perl use strict; use warnings; use Tk; my $mw = new MainWindow; # Main Window my $frm_name = $mw -> Frame(); my $lab = $frm_name -> Label(-text=>"Name:"); my $ent = $frm_name -> Entry(); my $but = $mw -> Button(-text=>"Push Me", -command =>\&push_button); my $textarea = $mw -> Frame(); #Creating Another Frame my $txt = $textarea -> Text(-width=>40, -height=>10); my $srl_y = $textarea -> Scrollbar(-orient=>'v',-command=>[yview => $t +xt]); my $srl_x = $textarea -> Scrollbar(-orient=>'h',-command=>[xview => $t +xt]); $txt -> configure(-yscrollcommand=>['set', $srl_y], -xscrollcommand=>['set',$srl_x]); $lab -> grid(-row=>1,-column=>1); $ent -> grid(-row=>1,-column=>2); $frm_name -> grid(-row=>1,-column=>1,-columnspan=>2); $but -> grid(-row=>4,-column=>1,-columnspan=>2); $txt -> grid(-row=>1,-column=>1); $srl_y -> grid(-row=>1,-column=>2,-sticky=>"ns"); $srl_x -> grid(-row=>2,-column=>1,-sticky=>"ew"); $textarea -> grid(-row=>5,-column=>1,-columnspan=>2); MainLoop; #This function will be executed when the button is pushed sub push_button { my $name = $ent -> get(); $txt -> insert('end',"Hello, $name."); }

Replies are listed 'Best First'.
Re: Perl/tk error I can't figure out
by bcrowell2 (Friar) on Feb 01, 2009 at 02:16 UTC

    I had to comment out the "use strict" and "use warnings" pragmata. After that, it worked. I wonder if there's something incompatible between your customized perl and Perl/Tk.

    In general, I don't think I'd advise anyone to start a new project with Perl/Tk today. It's had a history of sketchy support in the last few years, with major bugs being unfixed for long periods. I've written one big project in Perl/Tk, and although I found the API pleasant, the lack of active maintenance was really aggravating. Gtk2-perl is more modern, and probably also better maintained. The documentation isn't quite as good as perl/tk's but this tutorial is pretty good: http://forgeftp.novell.com//gtk2-perl-study/homepage/

      Hmm I did try commenting out the use strict but I hadn't thought of commenting use warnings as well so I just tried that. Unfortunatly that didn't work for me either. I've since reinstalled everything related to perl (I think) on my machine in case switching to threads support broke something I wasn't aware of but that didn't do it either. Considering the total lack of solutions all over the internet for this problem I wouldn't be the least bit surprised if it's some incompatibility or something that I have.

      Maybe I will give gtk2-perl a try. Last time I looked at an example script using it I was scared ;)

      I'm slowely but surely becomming a better perl programmer though so perhaps I won't be as terrified by the api now ;)

      What about wxPerl? Is it doing well these days?. All I really care about is having a fairly easy to use api that will make windows and widgits that happily conform to my window manager/decorator. I'm not determined to use TK in other words.

      Thanks

      EDIT: Well after a couple hours of playing around with the gtk2 module I've decided to just use that. It's not nearly as intimidating as it was a month ago so at least I seem to be learning ;-) ++ for the good advice!

      In case anyone else lands here from Google as I did, be advised that Perl/Tk is not dead. The bug described here was fixed in 2008. Certain popular repos are using outdated source code. It's best to build it yourself from CPAN source.

Re: Perl/tk error I can't figure out
by zentara (Cardinal) on Feb 01, 2009 at 15:22 UTC
    Your code works just fine for me on Linux. What exactly is your problem? If you are just starting to learn, you might be better off concentrating on Gtk2, as mentioned above. It is better than Tk, and has an active future.

    As far as your error

    no event type or button # or keysym

    It looks like you copy-and-pasted wrong, and got a end-of-line comment '#' somewhere in the code.


    I'm not really a human, but I play one on earth Remember How Lucky You Are
      > It looks like you copy-and-pasted wrong, and got a end-of-line comment '#' somewhere in the code.

      Yeah I thought that at first too.. Trust me it's no typo. I even tried downloading the file from the TK tutorial here in the tutorials section rather than copying just as a sanity check and it produced the same result. Must be something odd about my configuration that's all I can figure.

        something odd about my configuration that's all I can figure

        Yeah, if you google for "no event type or button # or keysym while executing", you will find that many others have reported this as an installation problem of one sort or another on certain platforms.


        I'm not really a human, but I play one on earth Remember How Lucky You Are
Re: Perl/tk error I can't figure out
by boblawblah (Scribe) on Feb 01, 2009 at 16:32 UTC
    I would suggest learning gtk-perl as well. It may look intimidating, but I find that it's api is more intuitive and easier to use. Gtk has a number features that Tk doesn't, and you will probably find that you want to use them as your gui programs grow more complex. Gtk also has a more modern, polished look to it. I'm not trying to knock Tk, it is a powerful toolkit, but I find that Gtk is much more rewarding.
      Yeah I think now that I've got the basics of perl down alot better Gtk really isn't as bad as I thought it was when I first looked at it. So far I've seen some examples already of really neat features that I'll have to find some sort of use for!

      I use KDE so my other original reason for being inclined to stay away from Gtk was that I like to have a unified look across all my apps. Thanks to the gtk theme engine for qt Gtk apps now look great so I think I'll be sticking with the Gtk for now! Thanks everyone