Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re^2: Tk ASCII Draw on Canvas

by Discipulus (Abbot)
on Jun 04, 2019 at 07:49 UTC ( #11100941=note: print w/replies, xml ) Need Help??

in reply to Re: Tk ASCII Draw on Canvas
in thread Tk ASCII Draw on Canvas

Thanks choroba for looking at my code.

> Canvas is designed to make moving objects around with a mouse easy. Therefore, when you press a button and start moving the mouse, the current is the canvas object that you're moving, i.e. it doesn't change as you move the mouse pointer over the grid.

The above seems very reasonable but i doubt is true: infact, if true, how can my code work? I currently have:

$canvas->Tk::bind("<Control-Motion>", [ \&set_coord, Ev('x'), Ev('y') ]);

and this code actually draws on the canvas and the element tagged as current changes as you move the pointer (you can also see the debug messages on the console like SET 22 - 14 and so on)

So with the Control modifier it works and as Button1 is stated as a valid modifier I expected to work in the same way. Here my working binding and all tries:

$canvas->Tk::bind("<Control-Motion>", [ \&set_coord, Ev('x'), Ev(' +y') ]); #no just the first: #$canvas->Tk::bind('<Button1-Motion>', [ \&set_coord, Ev('x'), Ev( +'y') ]); # no just the first #$canvas->Tk::bind('<B1-Motion>', [ \&set_coord, Ev('x'), Ev('y') +]); # wrong: extra characters after detail in binding at #$canvas->Tk::bind('<Button-1-Motion>', [ \&set_coord, Ev('x'), Ev +('y') ]); # wrong: bad event type or keysym "Button1" #$canvas->Tk::bind('<Button1><Motion>', [ \&set_coord, Ev('x'), Ev +('y') ]); # ok after Button-1 (not holding it) until for example Button-3 #$canvas->Tk::bind('<Button-1><Motion>', [ \&set_coord, Ev('x'), E +v('y') ]);

The last one is intriguing: it seems to be not a modifier but more a sequence. Anyway I'm happy with <Control-Motion> less carpal tunnel ;)

> To make the sterling and degree work, you must save the script as UTF-8 and add use utf8; towards the top.

Tadąaa! thanks! adding use utf8; on top made sterling and degree to work as expected. My utf8 foo is near to zero.. I did not even suspected the issue.

I've update my code with it ;)


There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11100941]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (10)
As of 2019-10-21 21:11 GMT
Find Nodes?
    Voting Booth?