Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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); }


What time is it? It's Camel Time!

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2016-10-28 03:14 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (374 votes). Check out past polls.