________________________________

From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
Daniel Burgaud
Sent: October-14-08 11:15 PM
To: Perl-Win32-Users
Subject: question on TK


>Hello,

>I am using TK and have multiple "MainWindow->new()" windows.
>
>My 1st problem is:
>How do I "disable" or "make invisible" (or any other means to prevent user
>from doing anything on these "disabled" windows?
>
>2nd problem is:
>How do I close a window without closing the whole application?

#############################

Unless there is a reason to use multiple MainWindows (very rare) then don't
do that; use multiple toplevel windows instead. This will solve your 2nd
problem automatically.

As for your 1st problem - it all depends on what you mean by disable. You
can hide a toplevel window by using the withdraw method. You can stop a
toplevel from being closed by using the protocol method. Both are documented
in Tk::Wm. You can disable "every" widget within the toplevel by walking
through each child widget and setting the state. etc. There are many
variations depending on what you wish to do.

Here is a small program to show you some of the different Toplevel/Wm
options.
################################
use Tk;
use strict;

my @state = qw/normal iconic withdrawn zoomed/;
my $type=1;
my $noDelete=0;
my $state='normal';
my @allTops;

my $mw=tkinit;
my $lf1 = $mw->Labelframe(-text=>'Toplevel Options')->pack;
my $lf2 = $mw->Labelframe(-text=>'State')->pack;
$lf1->Checkbutton(-text=>'Transient?',-variable=>\$type)->pack;
$lf1->Checkbutton(-text=>'No Delete?',-variable=>\$noDelete)->pack;

foreach my $s (@state) {
   $lf2->Radiobutton(-text=>"$s",-variable=>\$state, -value=>"$s")->pack;
}
$mw->Button(
  -text=>'New Toplevel',
  -command=>\&doTop,
  )->pack();

$mw->Button(
  -text=>'Restore all Withdrawn Windows',
  -command=>\&restore,
  )->pack();

MainLoop;

sub doTop {
    my $top = $mw->Toplevel;
        $top->transient($mw) if ($type);
        $top->state($state);
        if ($noDelete) {
          $top->protocol('WM_DELETE_WINDOW',sub{});
        }
    $top->Button(-text=>'Withdraw Me for 3 seconds',
          -command=>sub{
          $top->withdraw;
          $top->after(3000,sub{
             $top->deiconify;
                 $top->raise;
                 });
          })->pack;
          push (@allTops, $top);
}

sub restore {
   foreach my $t (@allTops) {
      if (Exists($t) and ($t->state eq 'withdrawn') ) {
              $t->deiconify;
                  $t->raise;
          }
   }
}
__END__
#################################

Jack




_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to