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

Dear Monks!

I want to show a message in my GUI application like "Your request is being processed..." in a dialog box which will disappear after the task is done - something like messageBox without buttons, that doesn't block the the applications waiting for user input that will be closed without after some time when the task is done

I looked on messageBox, dialog, dialogBox or TopLevel (but there are the windows buttons minimize and maximize)and also on some Splash screen modules but I cannot get it working with this characteristics

Any ideas (example code:) how to do it?

Tanks a lot!
dzon
  • Comment on Tk - non-blocking messageBox without buttons closing without user input

Replies are listed 'Best First'.
Re: Tk - non-blocking messageBox without buttons closing without user input
by Anonymous Monk on Sep 17, 2008 at 14:13 UTC
    read the source to Tk::Splashscreen and modify to suit your needs (its only 80 lines, not a lot of control logic)
      Like this
      #!/usr/local/bin/perl -w # adapted from # http://search.cpan.org/src/LUSOL/Tk-Splashscreen-1.0/splashscreen.pl package Tk::Splashinfo; use Tk::widgets qw/Toplevel/; use base qw/Tk::Toplevel/; Construct Tk::Widget 'Splashinfo'; sub Populate { my ( $self, $args ) = @_; $self->withdraw; $self->overrideredirect(1); $self->SUPER::Populate($args); } 1; package main; use Tk; use Tk::Splashscreen; use Tk::widgets qw/Photo Animation/; use strict; my $mw = MainWindow->new; $mw->Button( -text => 'Quit', -command => \&exit )->pack; { my $gif89 = Tk->findINC('anim.gif'); my $splash = $mw->Splashinfo(); my $animate = $splash->Animation( -format => 'gif', -file => $gif8 +9 ); $splash->Label( -image => $animate )->pack; $animate->set_image(0); $animate->start_animation(500); $splash->Popup; # show Splashscreen $mw->Button( -text => 'Kill splash', -command => sub { $splash->destroy } )->pack; } $mw->deiconify; # show calculator MainLoop;
Re: Tk - non-blocking messageBox without buttons closing without user input
by zentara (Cardinal) on Sep 17, 2008 at 16:22 UTC
    Try this:
    #!/usr/bin/perl -w use strict; use Tk; my $mw = tkinit; my $notification = $mw->Toplevel(); $notification->geometry('+400+400'); $notification->overrideredirect(1); # Remove window decorations $notification->withdraw; # Hide display window $notification->Label( -text => 'Your message displayed here.', -foreground => 'white', -background => 'black', -height => 5 )->pack; $mw->Button( -text => 'Display Notification Window', -command => \&display_note )->pack; MainLoop; sub display_note { $notification->deiconify; $notification->raise; # this is where you setup a condition to withdraw it $notification->after( 5000, \&hide_note ); } sub hide_note { $notification->withdraw; }

    I'm not really a human, but I play one on earth Remember How Lucky You Are
      It works, thank you!

      Maybe one more thing: what should I change, that it will look like the messageBox window (with the title bar, borders, ...) - now it is just a rectangle

      dzon
        Comment out the line:
        # $notification->overrideredirect(1); # Remove window decorations # and probably add #prevents window from closing on close icon press $notification->protocol('WM_DELETE_WINDOW' => sub { });

        I'm not really a human, but I play one on earth Remember How Lucky You Are