Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: perl/tk changing button commands

by hiseldl (Priest)
on Apr 22, 2003 at 21:38 UTC ( [id://252371]=note: print w/replies, xml ) Need Help??


in reply to perl/tk changing button commands

If you want to change the action of the button every time it is pressed, then you need to leave out the -command switch and bind the 'ButtonPress' action later. This will allow you to re-bind the action once you have pressed the button. Here's an example:

#!/usr/bin/perl use strict; use warnings; use Tk; my $main = MainWindow->new; my $text = $main->Scrolled('Text', -width=>'50' )->pack; my $button = $main->Button(-text=>'next', )->pack; $button->bind('<ButtonPress>', \&one); MainLoop; sub one { my $talk="One! Click for two.\n"; $text -> insert('1.0',"$talk"); $button->bind('<ButtonPress>', \&two); } sub two { my $talk="One! Click for three.\n"; $text -> insert('1.0',"$talk"); $button->bind('<ButtonPress>', \&three); } sub three { my $talk="One! Click for one.\n"; $text -> delete('1.0', 'end'); $text -> insert('1.0',"$talk"); $button->bind('<ButtonPress>', \&one); }

Cheers!

--
hiseldl
What time is it? It's Camel Time!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://252371]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (8)
As of 2024-04-23 16:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found