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

Hi monks, I am facing a problem with messageBox widget in Perl/Tk. I am calling messageBox for showing Error Alert, but that alert message remains as a top most window on the desktop in WINDOWS (I am running Active perl 5.8.8 on windows), inspite of pressing show desktop icon, untill Ok is pressed. I want to show that alert message only if corresponding window is active, not in all cases. I have tried attributes function with topmost=>0 option but that seems to be not working. Please help me....thanks in advance
use strict; use warnings; use Tk; use Tk::Entry; my $mw = new MainWindow; my $new_label = $mw -> Label(-text=>"Enter any character", -foreground=>"red", -font => "verdanafont 10 bold") -> pack(-side=>"top"); my $ent=$mw->Entry()->pack(); my $press = $mw -> Button(-text=>"Press Me", -command =>\&PressMe, -font => "verdanafont 10 bold") -> pack(-side=>"left",-padx=>"5", -ipadx=>"5"); MainLoop; sub PressMe { my $val = $ent->get(); if ($val =~ m/[a-zA-Z0-9]/) { my $response=$mw -> messageBox(-type=>"ok", -message=>"al +phanumeric entered",-icon=>"info",-title=> "info!!"); #$response->attributes(-topmost=>0); } return; }

Replies are listed 'Best First'.
Re: Problem with MessageBox Widget in Perl/Tk
by zentara (Cardinal) on Oct 30, 2008 at 19:34 UTC
    i am looking for work arounds

    This is a hack, but seems to work on linux. I noted 2 needed (but weird) focus calls, that I found by experimenting. :-)

    #!/usr/bin/perl use strict; use warnings; use Tk; use Tk::Entry; my $mw = new MainWindow; my $warning = 'alphanumeric entered'; my $tl = $mw->Toplevel(); $tl->geometry('300x100+300+300'); + my $wlabel= $tl->Label(-textvariable => \$warning) ->pack(-expand=>1,-fill=>'both'); $tl->withdraw; my $new_label = $mw -> Label(-text=>"Enter any character", -foreground=>"red", )-> pack(-side=>"top"); my $ent=$mw->Entry()->pack(); my $press = $mw -> Button(-text=>"Show Me", -command =>\&PressMe, )-> pack(-side=>"left",-padx=>"5", -ipadx=>"5"); $mw->bind( '<FocusOut>' => sub{ $tl->withdraw; $mw->focus; #hack needed to prevent recursion } ); $mw->bind( '<FocusIn>' => \&PressMe ); MainLoop; sub PressMe{ my $val = $ent->get(); if ($val =~ m/[a-zA-Z0-9]/) { $tl->deiconify; $tl->raise; $ent->focus; #hack needed to prevent recursion } return; }

    I'm not really a human, but I play one on earth Remember How Lucky You Are
      thanks zentara..but somehow it is not working.. well I have done something to get around of this problem... But now my problem is that i am not able to get the same error/info/warning icons as i was getting using MessageBox widget.Only simple perl built-in bitmaps, i am able to get. Please help if anybody knows how to get those icons.
      use strict; use warnings; use Tk; use Tk::Entry; our $mw = new MainWindow; our $main; my $new_label = $mw -> Label(-text=>"Enter any character", -foreground=>"red", -font => "verdanafont 10 bold") -> pack(-side=>"top"); my $ent=$mw->Entry()->pack(); my $press = $mw -> Button(-text=>"Press Me", -command =>\&PressMe, -font => "verdanafont 10 bold") -> pack(-side=>"left",-padx=>"5", -ipadx=>"5"); MainLoop; sub PressMe { my $val = $ent->get(); if ($val =~ m/[a-zA-Z0-9]/) { #my $response=$mw -> messageBox(-type=>"ok", -message=>"al +phanumeric entered",-icon=>"info",-title=> "info!!"); if (!Exists($main)) { $main = $mw->Toplevel; $main->geometry("250x100"); $main->transient($mw); $main->protocol('WM_DELETE_WINDOW' => sub {$main->destroy( +);}); #$main->Photo('-format'=>'jpeg', -file => "\@C:\\warn.jpg" +); #my $l=$main->Label(-image=>'hi')->pack; my $l = $main->Label(-bitmap=>"info")->pack(-side=>"left") +; my $ll=$main->Label(-text=>"Alpha numeric entered !")->pac +k(); } else { $main->deiconify(); $main->raise(); } } return; }
Re: Problem with MessageBox Widget in Perl/Tk
by Anonymous Monk on Oct 30, 2008 at 13:45 UTC
      thanks for giving your inputs... since i am new to Perl/tk i dont know how to create new widget. Thats why i am looking for work arounds, suggest me if you have any