#!/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('' => sub { button_down($txt) }); $bt->bind('' => 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"); }