Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Tk::Button: How do I trigger a callback when button is pressed (as opposed to released)?

by golux (Friar)
on Dec 26, 2012 at 04:31 UTC ( #1010315=note: print w/replies, xml ) Need Help??


in reply to Tk::Button: How do I trigger a callback when button is pressed (as opposed to released)?

Hi perltux,

Use Button-1 for button-down events (as opposed to ButtonRelease-1 for button-up events). For example:

#!/usr/bin/perl -w use strict; use warnings; use Tk; my $mw = new MainWindow(-title => 'Button press example'); my $bt = $mw->Button(-bg => '#ffefb5', -text => 'Press Me'); my $txt = $mw->Text(-bg => 'white'); $bt->pack($txt); $bt->bind('<Button-1>' => sub { button_down($txt) }); $bt->bind('<ButtonRelease-1>' => sub { button_up($txt) }); Tk::MainLoop; sub button_down { my ($text) = @_; my $time = localtime(time()); $text->insert("end", "$time: Button Down\n"); } sub button_up { my ($text) = @_; my $time = localtime(time()); $text->insert("end", "$time: Button Up\n"); }
say  substr+lc crypt(qw $i3 SI$),4,5
  • Comment on Re: Tk::Button: How do I trigger a callback when button is pressed (as opposed to released)?
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: Tk::Button: How do I trigger a callback when button is pressed (as opposed to released)?
by perltux (Scribe) on Dec 26, 2012 at 04:49 UTC
    Thanks, that works great!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1010315]
help
Chatterbox?
[Your Mother]: I like Manu Chao.
[Your Mother]: I like this one quite well, https://www. youtube.com/watch? v=rSEUH4KRfN8
[choroba]: Půlnoční Marie (which means Midnight Mary)
[choroba]: but the band is practically dead. We rehearse once in a year, and perform with the same frequency
[ambrus]: `quote
[ambrus]: sorry, typed in the wrong box
[LanX]: Your mother: je ne t'aime plus! ;)
[choroba]: seems lispy
[Your Mother]: Be nice! I speak that much French. Though I also like that song.
[choroba]: So, I joined Pod Černý Vrch some months ago to still have the fun. But I wouldn't call it "punk" anymore...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (14)
As of 2017-03-24 12:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (301 votes). Check out past polls.