Re: Binding images to mouseclicks



On Sep 19, 6:06 pm, elektrikbl...@xxxxxxxxx wrote:
On Sep 18, 7:01 pm, Bruce <doNOTmai...@xxxxxxxxxxx> wrote:

- Hide quoted text -
- Show quoted text -



elektrikbl...@xxxxxxxxx wrote:
hi,
i got an error while trying out the binding of widgets to mouse clicks
on a canvas. the script was as:
bind $my_canvas <1> {
 if {%x < $xmax && %y < $ymax} then {
   do_widget1
 } elseif {%x < $xmax2 && %y < $ymax2} then {
   do_widget2
 }
}
the error shown is "wrong number of args."
is it not possible to use if-else clause in the command portion of the
"bind" statement? or else can anyone tell me the possible cause and
solutions for this error?
any help is greatly appreciated...
regards,
elektrikblues
copy/paste the entire error message it will tell you where the wrong # args is being applied.
the bind command above is syntactically correct and will work - as long as the global variable xmax,
ymax,xmax2,ymax2 exist and do_widget1/do_widget2 are defined and take no arguments.
but the logic seems weird. you say you are trying to bind to an image, but instead you bind
to the canvas itself and do your own intersection (and the intersection logic seems wrong unless
both of you images start at the origin (top left) of the canvas.
The canvs can do all of this work for you. instead of using the system bind on the canvas widget
use the bind sumcommand of the widget and bind directly to you item. Then the canvas handles
all the intersection code.
$my_canvas create image $x $y -image $my_image1 -tag PressMe
$my_canvas bind PressMe <1> do_press
Bruce

hi,
as per your suggestion, i changed the canvas bindings to the
following.

canvas .cns
set selid 11
.cns bind tag1 <1> {
  global sid
  set sid 11
  tk_popup .popupMenu %X %Y
  }

.cns bind tag2 <1> {
  global sid
  set sid 12
  tk_popup .popupMenu %X %Y
  }

set m [menu .popupMenu]
$m add radiobutton -label 0  -variable x$sid -value "0" -command
{c_process$sid}
$m add radiobutton -label 1  -variable x$sid -value "1" -command
{c_process$sid}

for each tag, i have an independent process as well as an associated
variable that is,
for tag1, the process is "c_process11" and variable is "x11"
for tag2, the process is "c_process12" and variable is "x12"

while running the script, the first binding works fine. but when i
click on the second tag object, the changes are happening to the first
one only. the value of the variable "sid" is not at all being updated
at the global scope. as a result the process still points to
"c_process11" and the variable points to "x11" itself. how can i make
it update itself depending upon the mouseclicks?

pls suggest a solution for this..

thanks in advance,
elektrikblues



oops!!! a newline came in by mistake between the "-command" option and
the associated command in the radiobuttons. pls consider it as a bug
only. :)

elektrikblues
.



Relevant Pages

  • Fwd: (fwd) binding to a derived canvas widget
    ... I'm working on a canvas based module to simulate the ... which just created a new CanvasDirTree widget, derived from a Canvas, ... bind Button-1, to activate the animation, and select a sub-directory. ... because I'm binding to everything ...
    (comp.lang.perl.tk)
  • Re: Embedding images in widgets
    ... canvas and make it behave like a widget? ... to places images on the canvas. ... man bind - in a simplest case, ... being shown regarding the number of args in the bind statement itself. ...
    (comp.lang.tcl)
  • Re: Binding images to mouseclicks
    ... the bind command above is syntactically correct and will work - as long as the global variable xmax, ... to the canvas itself and do your own intersection (and the intersection logic seems wrong unless ... use the bind sumcommand of the widget and bind directly to you item. ... global sid ...
    (comp.lang.tcl)
  • Re: Embedding images in widgets
    ... canvas and make it behave like a widget? ... to places images on the canvas. ... man bind - in a simplest case, ... How many args does do_widget1 or do_widget2 expect? ...
    (comp.lang.tcl)
  • Re: Binding images to mouseclicks
    ... the bind command above is syntactically correct and will work - as long as the global variable xmax, ... to the canvas itself and do your own intersection (and the intersection logic seems wrong unless ... use the bind sumcommand of the widget and bind directly to you item. ...
    (comp.lang.tcl)