Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Tk how-to?

by BrowserUk (Pope)
on Dec 04, 2005 at 13:54 UTC ( #513952=perlquestion: print w/replies, xml ) Need Help??

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

How does one run the Tk; demos?

Update: Would one of the 3 people who downvoted this post please explain to me, by /msg, or anonymous monk post if need be, why it warranted a downvote?

I invite all three of you to expend all your votes every day downvoting very node here, but do please explain why this one warranted it?


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re: Tk how-to?
by thundergnat (Deacon) on Dec 04, 2005 at 14:34 UTC

    Run the 'widget' script in the Perl/bin directory.

      Thanks++. I search for everything starting with 'tk', and read UserGuide, WidgetDemo and browsed the sources of a dozen or more. If this is mentioned anywhere, I didn't find it.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        perldoc Tk::UserGuide
        NAME
          Perl/Tk - Writing Tk applications in Perl 5

        DESCRIPTIONJ
          This document is for beginners. It assumes you know some Perl, and have
          it and Tk running. If you are *not* currently reading this document
          courtesy of the widget demonstration program, please be sure to run
          widget, as it will show you the various widget types supported by Tk and
          how to use them. widget should be installed in your default path, so
          type *widget* at a command prompt
        .

        MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
        I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
        ** The third rule of perl club is a statement of fact: pod is sexy.

Re: Tk how-to?
by converter (Priest) on Dec 04, 2005 at 14:17 UTC
    I have a nice collection of Tk-related links on my home node. I'm sure you'll find more than enough there to get you started down the road of Tk madness.

      Nice collection of links. You don't know of one that describes how to bind to a Canvas redraw event do you?


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        Greetings BrowserUk!

        I just recently came across the infamous Canvas bind problem again.

        According to Mastering Perl/Tk (published by O'Reilly), you need to use a different bind method with a Canvas object, called CanvasBind.  (This is described in chapter 9.4, and it's because a Canvas object has its own bind method).

        Here's an example program I created to demonstrate.  When you resize the main window (and thus the Canvas object), it draws random squares as a result of the change in size and/or position (the event for which is a "<Configure>"):

        #!/usr/bin/perl -w + # Strict use strict; use warnings; + # Libraries use Tk; + # Subroutines sub random($) { int rand $_[0] } sub random_square($) { my $can = shift; my ($x0, $y0, $x1, $y1) = (random 256, random 256, random 256, ran +dom 256); $x1 += $x0; $y1 += $y0; my $bg = sprintf "#%02x%02x%02x", random 256, random 256, random 2 +56; $can->createRectangle($x0, $y0, $x1, $y1, -fill => $bg); } # Main program my $mw = new MainWindow(-title => "Canvas binding test"); my $can = $mw->Canvas(-bg => 'white', -width => 512, -height => 512); $can->pack(-expand => 1, -fill => 'both'); $can->CanvasBind('<Configure>', [\&random_square]); MainLoop;

        @ARGV=split//,"/:L"; map{print substr crypt($_,ord pop),2,3}qw"PerlyouC READPIPE provides"
Re: Tk how-to?
by zentara (Archbishop) on Dec 04, 2005 at 17:31 UTC
    Yeah, it's not intuitive. :-) The Zinc demo is called "zinc-demos", and the gtk demo is called "gtk-demo". Maybe Tk should follow suit ... tk-demo ?

    I'm not really a human, but I play one on earth. flash japh
Re: Tk how-to?
by davidrw (Prior) on Dec 04, 2005 at 14:42 UTC

      I just wanted to know how to run the demos.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Tk how-to?
by Courage (Parson) on Dec 04, 2005 at 22:19 UTC
    Your direct question was already answered, I only want to note to you that a very similar to perl/Tk module Tcl::Tk is a bit harder to use at the beginning, but a much more flexible and capable, so, if you're starting, better to use it.
    There were some show-stoppers in perl/Tk that made me move to Tcl::Tk.
    (I am one of a maintainer of it, BTW)

    Best regards,
    Courage, the Cowardly Dog

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://513952]
Approved by wfsp
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2021-05-14 11:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (150 votes). Check out past polls.

    Notices?