Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
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 perusing the Monastery: (10)
As of 2014-07-10 23:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (217 votes), past polls