Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: perl/tk changing button commands

by hiseldl (Priest)
on Apr 22, 2003 at 21:38 UTC ( #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!


Comment on Re: perl/tk changing button commands
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (18)
As of 2015-07-02 18:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (44 votes), past polls