binding right mouse button click to all buttons 
Author Message
 binding right mouse button click to all buttons
Hi,

I'm trying to bind the right mouse button click to do sth for all the
buttons
in my main window.

use Tk;
use Tk::Button;

my $main = new MainWindow;

$b = $main->Button(-text=>"click", -command=>\&exit)->pack;

$main->bind('Tk::Button', '<ButtonRelease-3>', \&some_sub);

This doesn't seem to be working.
Is ButtonRelease-3 not the right mouse button release or is there some other
mistake here?

Thanks for the help,

J.



Sun, 13 Mar 2005 17:10:14 GMT  
 binding right mouse button click to all buttons
 this might help

$var->bind('<Button-3>', sub{ &dosth});



Sun, 13 Mar 2005 20:37:48 GMT  
 binding right mouse button click to all buttons
yep, I know, thanks.

But I thought I could bind an action to a class such as Tk::Button,
so that I don't have to state the binding every time sth of that class is
created.

Maybe

$main->bind('tk::Button', '<Button-3>', sub {$some_sub});

Will try.

Thanks.

J.


Quote:
> this might help

> $var->bind('<Button-3>', sub{ &dosth});



Sun, 13 Mar 2005 21:01:52 GMT  
 binding right mouse button click to all buttons

Quote:
> yep, I know, thanks.

> But I thought I could bind an action to a class such as Tk::Button,
> so that I don't have to state the binding every time sth of that class is
> created.

Did you press the right (no pun intended) button ? The reason I ask is because I
put together this following test script, which didn't work (duh!) until I
pressed the right button :-)
############################
use Tk;
use strict;

my $main = new MainWindow;

for my $i (0..9){
   $main->Button(-text=>"click")->pack;

Quote:
}

$main->bind('Tk::Button', '<ButtonRelease-3>', \&some_sub);

MainLoop;

sub some_sub
{
 print scalar gmtime,"\n";

Quote:
}

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


Sun, 13 Mar 2005 23:04:53 GMT  
 binding right mouse button click to all buttons
eurm,

thanks. It was due to a misspelling in the code.

$main->bind('Tk::Button', '<ButtonRelease-3>', \&some_sub);

but then:

sub sone_sub {
    ...

Quote:
}

But shouldn't I get an error saying that the sub &some_sub
doesn't exist??


Quote:


> > yep, I know, thanks.

> > But I thought I could bind an action to a class such as Tk::Button,
> > so that I don't have to state the binding every time sth of that class
is
> > created.

> Did you press the right (no pun intended) button ? The reason I ask is
because I
> put together this following test script, which didn't work (duh!) until I
> pressed the right button :-)
> ############################
> use Tk;
> use strict;

> my $main = new MainWindow;

> for my $i (0..9){
>    $main->Button(-text=>"click")->pack;
> }

> $main->bind('Tk::Button', '<ButtonRelease-3>', \&some_sub);

> MainLoop;

> sub some_sub
> {
>  print scalar gmtime,"\n";
> }

> ############################



Sun, 13 Mar 2005 23:46:23 GMT  
 binding right mouse button click to all buttons

Quote:

> eurm,

> thanks. It was due to a misspelling in the code.


> $main->bind('Tk::Button', '<ButtonRelease-3>', \&some_sub);

> but then:

> sub sone_sub {
>     ...
> }

> But shouldn't I get an error saying that the sub &some_sub
> doesn't exist??

I get an error:

Tk::Error: Undefined subroutine &main::sone_sub called at /usr/perl5.8.0/lib/site_perl/5.8.0/i386-freebsd-64int/Tk.pm line 340.
 (command bound to event)

If you want the error message on compile time, then you should use
lexicals and "use strict":

  my $some_sub = sub {
    ...
  };
  $main->bind('Tk::Button', '<ButtonRelease-3>', $some_sub);

Regards,
        Slaven

- Show quoted text -

Quote:





> > > yep, I know, thanks.

> > > But I thought I could bind an action to a class such as Tk::Button,
> > > so that I don't have to state the binding every time sth of that class
> is
> > > created.

> > Did you press the right (no pun intended) button ? The reason I ask is
> because I
> > put together this following test script, which didn't work (duh!) until I
> > pressed the right button :-)
> > ############################
> > use Tk;
> > use strict;

> > my $main = new MainWindow;

> > for my $i (0..9){
> >    $main->Button(-text=>"click")->pack;
> > }

> > $main->bind('Tk::Button', '<ButtonRelease-3>', \&some_sub);

> > MainLoop;

> > sub some_sub
> > {
> >  print scalar gmtime,"\n";
> > }

> > ############################

--

Tired of using file selectors? Real programmers use the TAB key for
completion and not for jumping around. Try
        http://search.cpan.org/search?mode=module&query=Tk::PathEntry


Mon, 14 Mar 2005 07:41:35 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Binding right mouse button for Tk::Tree items

2. overriding default right mouse button binding for text widget

3. Right-clicking buttons in Perl/TK

4. HList selection with right mouse button?

5. Tree and mouse right button

6. mouse right click

7. Mouse Click Bind for an Entry Widget

8. binding mouse clicks to Tk::Columns

9. Please help: Binding mouse click to tree entry.

10. Binding a right-click in a text widget

11. Tkperla4 w/ patches: menutest core dumps on mouse button press

12. avoid double-click on submit button

 

 
Powered by phpBB® Forum Software