Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Tk - removing a message box automatically

by crabbdean (Pilgrim)
on Mar 25, 2004 at 04:23 UTC ( #339637=perlquestion: print w/replies, xml ) Need Help??
crabbdean has asked for the wisdom of the Perl Monks concerning the following question:

Hi Fellow Monks,

I want to remove a message box automatically after so-many milliseconds. Simple problem really but messagebox widgets require a user response. With it waiting for user response you can't get it to proceed onto the next command, which would be a removal command using the "after" method. I just want to display it for a bit and then remove it. I know overlooking something obvious.

The Funkster of Mirth
Programming these days takes more than a lone avenger with a compiler. - sam
RFC1149: A Standard for the Transmission of IP Datagrams on Avian Carriers
  • Comment on Tk - removing a message box automatically

Replies are listed 'Best First'.
•Re: Perl::Tk - removing a message box automatically
by merlyn (Sage) on Mar 25, 2004 at 04:29 UTC
    Well, the answer is not to use a Tk::messageBox. {grin}

    You can create a new Toplevel, populate it, and tell it to destroy itself after a time passes. For example (untested):

    my $box = $mw->Toplevel; my $message = $box->ROText->pack; $message->insert(end => "Hey there! Gotta go!"); $box->after(3000, sub { shift->destroy });

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

Re: Perl::Tk - removing a message box automatically
by pg (Canon) on Mar 25, 2004 at 04:40 UTC

    However this is not something people usually do in GUI design.

    It is about what amount of attention you want to draw from the user. If you don't need that much, most likely you really don't need a popup; if you really need that much attention, the right way is to let people click (this is not about to distract people, but to CONFIRM that the user noticed the popup.)

Re: Tk - removing a message box automatically
by zentara (Archbishop) on Mar 25, 2004 at 14:58 UTC
    How's this? You could use the same idea to destroy the $messagebox.
    #!/usr/bin/perl use Tk; use strict; my $text = 'Hello World..... How\'s this for fun!! '; my $mw = tkinit; $mw->geometry('+20+20'); $mw->overrideredirect(1); my $label = $mw->Label( -textvariable=>\$text, -font=>'courier', -bg=>'green', -bd=>4, -relief=>'ridge' )->pack(-fill=>'both'); $label->bind('<ButtonRelease>',sub{$mw->destroy}); $mw->repeat(60,[sub{$text=~s/(.)(.*)/$2$1/;}]); $mw-> after(5000, [sub{Tk::exit}]); # autoclose in 5000 milisecs + MainLoop;

    I'm not really a human, but I play one on earth. flash japh

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://339637]
Approved by kvale
Front-paged by matija
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2018-06-19 01:47 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (111 votes). Check out past polls.