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

Does anyone know of an online tutorial that talks about the use of the Tcl::Tk module with. I have looked at the manpages and the documentation in Tcl.pm and Tk.pm The examples in there work quite happily, but I am getting stuck with creating entry widgets and using a button to e.g. disply the sum of two numbers entered. The funny thing is that I can write the correct script for wish. Perl (bless it's heart :)) does not seem to like things like;
entry(".e", -textvariable => var1); entry(".e2, -textvarible => var2); entry(".e3", -textvariable => var3); button(".b", -command => {set var3 [expr $var1 + $var2]}); tkpack ".e"; tkpack ".e2"; tkpack ".e3"; tkpack ".b"; MainLoop;
Take all the perl bits out and you have a wish script that works perfectly. Perl complains (under -w switch) that var1 and var2 are used once only and that var3 is not initialised. If anyone could give me some pointers I would be eternally grateful. Regards to all Perl Monks.

Replies are listed 'Best First'.
Re: Tcl::Tk module
by spudzeppelin (Pilgrim) on Jun 14, 2000 at 19:42 UTC
    Why not just write the thing in Perl/Tk instead, and forget the Tcl? Then your script would look something like:
    use Tk; $mw = MainWindow->new; $mw->title('Sample'); $e1 = $mw->Entry(-textvariable => \$var1)->pack(); $e2 = $mw->Entry(-textvariable => \$var2)->pack(); $e3 = $mw->Entry(-textvariable => \$var3)->pack(); $b = $mw->Button(-command => sub { $var3 = $var1 + $var2; })->pack(); MainLoop;
    Spud Zeppelin * spud@spudzeppelin.com
      Nice example spud, you get a star!
Re: Tcl::Tk module
by gnat (Beadle) on Jun 14, 2000 at 22:42 UTC
    I have to agree with Spudz. Perl::Tk is sweet for the GUI stuff. The only hassle is that you not only have to learn Tk, but how the Tcl interface is reimplemented in Perl. It's not an easy transition, I've found, and I really liked the "Learning Perl/Tk" book for that reason. Others didn't like the writing style, though, so buyer beware. For better or worse, though, it is the only one-stop-shop for learning about Perl/Tk.
RE: Tcl::Tk module
by le (Friar) on Jun 14, 2000 at 18:33 UTC
    IIRC you have to write references to variables to get them, just like:
    -textvarible => \$bla
    Maybe this helps a little.