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

Non blocking a Dialog box in Perl Tk

by lakshmananindia (Chaplain)
on Apr 23, 2010 at 12:39 UTC ( [id://836513]=perlquestion: print w/replies, xml ) Need Help??

lakshmananindia has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

I am in the process of writing a program which alerts the user when a Mail is received by an IMAP server. I alert the user by displaying a Dialog box.

But what happens is, the program is getting blocked until, the user presses the ok buttoon

But I want to continue my program, even if the user didn't give input. I searched in perlmonks and I got posts regarding to use the splash screen

I've tried the following sample program

#!/usr/bin/perl -w use strict; use Tk; my $mw = tkinit; $mw->withdraw(); my $i=0; my $k=0; while (1) { my $notification = $mw->Toplevel(); $notification->geometry("+$i+$k"); $i+=10; $k+=5; $notification->protocol('WM_DELETE_WINDOW' => sub { $notificat +ion->withdraw; }); $notification->Label( -text => 'Your message displayed here.', -height => 5 )->pack; $notification->withdraw; $notification->deiconify; $notification->raise; $notification->update(); $mw->after(5000); }

The code works. It display a new window in the given geomentry

Now If I click the close button in any one of the splash screen, I want to close only that splash screen

Can someone suggest how to do that??

I also wanted to know, is there any ways to make the dialog box to non-blocking??

--Lakshmanan G.

The great pleasure in my life is doing what people say you cannot do.


Replies are listed 'Best First'.
Re: Non blocking a Dialog box in Perl Tk
by thundergnat (Deacon) on Apr 23, 2010 at 16:35 UTC

    Dialog (and the derived DialogBox) does a non configurable global grab in its Show method so no, other than sub-classing and using a substitute Show method, you can't make Dialog non-blocking.

    However, it would be trivial to write your own version of a non-blocking "Dialog" pop up window. Something like this should give you a starting point.

    #!/usr/bin/perl use warnings; use strict; use Tk; my $mw = tkinit; $mw->update; my $number; notify( $mw, "Notification Window #" . ++$number, 4000 ); $mw->repeat( 5000, sub { notify( $mw, "Notification Window #" . ++$number, 4000 ) } ) +; MainLoop; sub notify { my ( $mw, $message, $ms ) = @_; my $notification = $mw->Toplevel(); $notification->transient($mw); $notification->overrideredirect(1); $notification->Popup( -popanchor => 'c' ); my $frame = $notification->Frame( -border => 5, -relief => 'groove +' )->pack; $frame->Label( -text => $message, )->pack( -padx => 5 ); $frame->Button( -text => 'OK', -command => sub { $notification->destroy; undef $notification +}, )->pack( -pady => 5 ); $notification->after( $ms, sub { $notification->destroy } ); }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://836513]
Approved by moritz
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (2)
As of 2024-04-26 01:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found