For Programmers: Free Programming Magazines  


Home > Archive > PerlTk > June 2007 > Balloon to get removed afer sometime









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Balloon to get removed afer sometime
nishant

2007-06-08, 8:02 am

Hi ,
I am posting a balloon.I want that the balloon should get destroyed
after some time , say 5 seconds if no action is done with the
mouse(mouse not moved etc...).
Pls help me in doing the same !!!

Ch Lamprecht

2007-06-08, 7:08 pm

nishant schrieb:
> Hi ,
> I am posting a balloon.I want that the balloon should get destroyed
> after some time , say 5 seconds if no action is done with the
> mouse(mouse not moved etc...).
> Pls help me in doing the same !!!
>

Hi,

here is an example, that shows how to delay a callback based on mouse movements.
The ballon part is left to you ...

HTH, Christoph

use strict;
use warnings;
use Tk;

my $mw = tkinit;
my $text='';
my $lab = $mw->Label(-textvariable=>\$text)->pack;
$mw->Button(-text =>'switch to standard event',
-command=>sub{
$mw->bind('<Motion>',\&process_event);
})->pack;
$mw->Button(-text =>'switch to delayed event',
-command=>sub{
$mw->bind('<Motion>',\&delayed_event);
})->pack;
MainLoop();

{
my $ev;
sub delayed_event{
my $w = shift;
my $timer = 1000;
$ev->cancel if $ev;
$ev = $w->after($timer,[\&process_event,$w])
}
}

sub process_event{
my $w= shift;
my $e = $w->XEvent();
my ($x,$y)=($e->x,$e->y);
$text= "x:$x y:$y";
}



--
use Tk;use Tk::GraphItems;$c=tkinit->Canvas->pack;push@i,Tk::GraphItems->
TextBox(text=>$_,canvas=>$c,x=>$x+=70,y=>100)for(Just=>another=>Perl=>Hacker);
Tk::GraphItems->Connector(source=>$i[$_],target=>$i[$_+1])for(0..2);
$c->repeat(30,sub{$_->move(0,4*cos($d+=3.16))for(@i)});MainLoop
nishant

2007-06-11, 4:03 am

Thnx a tonn !!! Works .....

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com