Problem on binding, 
Author Message
 Problem on binding,

Hi, everyone,

I try to bind a checkbutton to toggle the state of a menu button (normal
or disable). But, it does not work for me. Also, when the menubutton is
in "disabled" state, it still responses to user mouse click. In the
STDOUT window, it shows following error.

Tk::Error: Can't call method "cget" on an undefined value at
C:\Perl\site\lib/Tk/Menubutton.pm line 325. (command bound to event)

I did seen Slaven's previous mail mentioned there is a patch for this
fix. But I can find anywhere. I am using AS Perl 509 build and Tk800.011
from AS Package repository on win98.

Thanks a lot in advance.

Wei,

Here is the code I tested.

#!/usr/local/bin/perl -w

use strict;
use Tk;
use Tk::Menu;

my $MW = MainWindow->new();
$MW->title('Toggle Button State');

my $bvar=0;

my ($var1,$var2)=(1,1);

my
$cb=$MW->Checkbutton(-text=>'test',-variable=>\$bvar,-relief=>'flat');
my
$pcb=$MW->Menubutton(-text=>'checkmarks',-relief=>'raised',-state=>'disabled');

$cb->grid($pcb,-pady=>10);

$cb->bind('<Button1-ButtonPress>'=>[\&togglebstate,$pcb,$bvar]);

$pcb->checkbutton(-label=>'choice1',-variable=>\$var1);
$pcb->checkbutton(-label=>'choice2',-variable=>\$var2);

MainLoop;

sub togglebstate {

  if ((defined $butvar) && ($butvar == 1)) {
 $pcbref->configure(-state=>'normal');
   } else {
 $pcbref->configure(-state=>'disabled');
   }

Quote:
}

__END__


Sun, 08 Jul 2001 03:00:00 GMT  
 Problem on binding,
Hi, everyone,

I try to bind a checkbutton to toggle the state of a menu button (normal
or disable). But, it does not work for me. Also, when the menubutton is
in "disabled" state, it still responses to user mouse click. In the
STDOUT window, it shows following error.

Tk::Error: Can't call method "cget" on an undefined value at
C:\Perl\site\lib/Tk/Menubutton.pm line 325. (command bound to event)

I did seen Slaven's previous mail mentioned there is a patch for this
fix. But I can find anywhere. I am using AS Perl 509 build and Tk800.011
from AS Package repository on win98.

Thanks a lot in advance.

Wei,

Here is the code I tested.

#!/usr/local/bin/perl -w

use strict;
use Tk;
use Tk::Menu;

my $MW = MainWindow->new();
$MW->title('Toggle Button State');

my $bvar=0;

my ($var1,$var2)=(1,1);

my
$cb=$MW->Checkbutton(-text=>'test',-variable=>\$bvar,-relief=>'flat');
my
$pcb=$MW->Menubutton(-text=>'checkmarks',-relief=>'raised',-state=>'disabled');

$cb->grid($pcb,-pady=>10);

$cb->bind('<Button1-ButtonPress>'=>[\&togglebstate,$pcb,$bvar]);

$pcb->checkbutton(-label=>'choice1',-variable=>\$var1);
$pcb->checkbutton(-label=>'choice2',-variable=>\$var2);

MainLoop;

sub togglebstate {

  if ((defined $butvar) && ($butvar == 1)) {
 $pcbref->configure(-state=>'normal');
   } else {
 $pcbref->configure(-state=>'disabled');
   }

Quote:
}

__END__


Sun, 08 Jul 2001 03:00:00 GMT  
 Problem on binding,

Quote:

> Hi, everyone,

> I try to bind a checkbutton to toggle the state of a menu button (normal
> or disable). But, it does not work for me. Also, when the menubutton is
> in "disabled" state, it still responses to user mouse click. In the
> STDOUT window, it shows following error.

> Tk::Error: Can't call method "cget" on an undefined value at
> C:\Perl\site\lib/Tk/Menubutton.pm line 325. (command bound to event)

> I did seen Slaven's previous mail mentioned there is a patch for this
> fix. But I can find anywhere. I am using AS Perl 509 build and Tk800.011
> from AS Package repository on win98.

It's easier to use the -command argument for the checkbutton than the
binding (which doesn't seem to be right). I also changed the
subroutine call to use the perl anonymous subroutine notation. Now the
code should work.

The response in disabled mode seems to be an activestate problem,
since it does not appear on Unix.

#!/usr/local/bin/perl -w

use strict;
use Tk;
use Tk::Menu;

my $MW = MainWindow->new();
$MW->title('Toggle Button State');

my $bvar=0;

my ($var1,$var2)=(1,1);

my
$pcb=$MW->Menubutton(-text=>'checkmarks',-relief=>'raised',-state=>'disabled');
my $cb;
$cb=$MW->Checkbutton(-text=>'test',-variable=>\$bvar,-relief=>'flat',
                    -command => sub { togglebstate($cb,$pcb,$bvar)});

$cb->grid($pcb,-pady=>10);

$pcb->checkbutton(-label=>'choice1',-variable=>\$var1);
$pcb->checkbutton(-label=>'choice2',-variable=>\$var2);

MainLoop;

sub togglebstate {

  if ((defined $butvar) && ($butvar == 1)) {
 $pcbref->configure(-state=>'normal');
   } else {
 $pcbref->configure(-state=>'disabled');
   }

Quote:
}

__END__

Regards,
        Slaven

--
use Tk;$c=tkinit->Canvas->pack;$x=45;for(split/_/,'KPI1_+09IPK_K;-OA1_+K!;A__1;
Q!7G_1+QK_3CLPI90,_+K!;A_+1!KQ!.N_K+1Q!.F_1+KN.Q__1+KN._K+1Q!.F_1+KN.Q_+1Q__+1!
KQ!.N_1;Q!7G_K3,09Q_+1!K.Q_K+1Q!.F_1+KN.Q'){s/\n//g;for(split/!/){$c->create(
'line',map{$a=-43+ord;($x+($a>>3)*2,123+($a&7)*2)}split//)}$x+=12}MainLoop



Mon, 09 Jul 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Problem with bind() on perl 4.0.1.6 with CRAY/UNICOS

2. Problem with binding events on TkPerl canvas

3. Problem with bind() under Solaris (not the FAQ)

4. Some problem with bindings...

5. Key repeat problem in bindings.

6. Problem with binding

7. problem in binding keys?

8. Problem using bind()

9. HELP - bind does not bind

10. Net::LDAP bind or bound?

11. PERLFUNC: bind - binds an address to a socket

12. PERLFUNC: bind - binds an address to a socket

 

 
Powered by phpBB® Forum Software