Problem with binding events on TkPerl canvas 
Author Message
 Problem with binding events on TkPerl canvas

I already posted this to the nTk mailing list, but somewhere along the way
the body of my message keeps getting deleted, so I'm trying here now...

I'm starting to look at porting some of my code from TkPerl5a5 to the
new Tk4-based TkPerl.  But right now I can't figure out how to bind
events in a canvas widget.  I can bind events that happen over any _item_
in the canvas, for example:

        $canvas->bind('all', '<Button-1>' => sub {print "hi\n";} );

but what I want is to bind events that happen _anywhere_ on the canvas.
In TkPerl5a5, I would do:

        tkbind($canvas, '<Button-1>' => sub {print "hi\n";} );

and in Tcl/Tk (I think):

        bind .canvas <Button-1> {puts "hi"}

but my best guess at this in the new TkPerl is:

        $canvas->bind('<Button-1>' => sub {print "hi\n";} );

which refuses to run, giving me the error message "no binding
exists for "CODE(0x134a54)"" for that line.  

So, does the canvas bind method insist on three arguments, the first of
which is is a TagOrID?  If so, how can I do what I want?  Or am I doing
something wrong?  Or does the above code work for other people?

                                                thanks for any help,
                                                Gregg Helt



Mon, 13 Oct 1997 03:00:00 GMT  
 Problem with binding events on TkPerl canvas

:
:
:I already posted this to the nTk mailing list, but somewhere along the way
:the body of my message keeps getting deleted, so I'm trying here now...

Sorry about that not my site ...

:
:I'm starting to look at porting some of my code from TkPerl5a5 to the
:new Tk4-based TkPerl.  But right now I can't figure out how to bind
:events in a canvas widget.  I can bind events that happen over any _item_
:in the canvas, for example:
:
:        $canvas->bind('all', '<Button-1>' => sub {print "hi\n";} );
:
:but what I want is to bind events that happen _anywhere_ on the canvas.
:In TkPerl5a5, I would do:
:
:        tkbind($canvas, '<Button-1>' => sub {print "hi\n";} );

:
:and in Tcl/Tk (I think):
:
:        bind .canvas <Button-1> {puts "hi"}
:
:but my best guess at this in the new TkPerl is:
:
:        $canvas->bind('<Button-1>' => sub {print "hi\n";} );
:
:which refuses to run, giving me the error message "no binding
:exists for "CODE(0x134a54)"" for that line.  
:
:So, does the canvas bind method insist on three arguments, the first of
:which is is a TagOrID?  

It does.

: If so, how can I do what I want?

In Tk-b3 you pass explicit package method to call base Tk widget method
rather than Tk::Canvas::bind:

   $canvas->Tk::bind('<Button-1>' => sub {print "hi\n";} );



Mon, 13 Oct 1997 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Binding mouse event to a canvas

2. help binding mouse events to canvas

3. binding an event to an item in a canvas widget

4. TkPerl problems with canvas

5. problem binding keys on a canvas

6. TKPerl: Postscript method for canvas widget

7. TKperl - can't get canvas addtag to work

8. tkperl scrollbar canvas

9. Key bindings with TkPerl

10. Tkperl: How do you get bindings from inheritance?

11. tkperl default binding question !!

12. overriding tkperl default key bindings?

 

 
Powered by phpBB® Forum Software