Hi,
moving graphical objects on a canvas
is quite easy. But how can I manage to
move common widgets as labels or
frames on a canvas?
The following examples works well
with circles, lines etc. but not
with an label. So where is my mistake?
Mycroft
********************
proc dragstart {w x y} {
global draglocation
catch {unset draglocation}
set draglocation(obj) [$w find closest $x $y]
set draglocation(x) $x
set draglocation $y
}
proc dragit {w x y} {
global draglocation
if {"$draglocation(obj)" != ""} {
set dx [expr $x - $draglocation(x)]
set dy [expr $y - $draglocation]
$w move $draglocation(obj) $dx $dy
set draglocation(x) $x
set draglocation $y
}
}
canvas .c -width 400 -height 400
.c create oval 20 30 40 50 -fill red -stipple gray25 -tags {movable}
.c create window 150 150 -tags {movable} -window [label .c.button -text hallo]
.c bind movable <Button-1> {dragstart %W %x %y}
.c bind movable <B1-Motion> {dragit %W %x %y}
pack .c
*********************
moving graphical objects on a canvas
is quite easy. But how can I manage to
move common widgets as labels or
frames on a canvas?
The following examples works well
with circles, lines etc. but not
with an label. So where is my mistake?
Mycroft
********************
proc dragstart {w x y} {
global draglocation
catch {unset draglocation}
set draglocation(obj) [$w find closest $x $y]
set draglocation(x) $x
set draglocation $y
}
proc dragit {w x y} {
global draglocation
if {"$draglocation(obj)" != ""} {
set dx [expr $x - $draglocation(x)]
set dy [expr $y - $draglocation]
$w move $draglocation(obj) $dx $dy
set draglocation(x) $x
set draglocation $y
}
}
canvas .c -width 400 -height 400
.c create oval 20 30 40 50 -fill red -stipple gray25 -tags {movable}
.c create window 150 150 -tags {movable} -window [label .c.button -text hallo]
.c bind movable <Button-1> {dragstart %W %x %y}
.c bind movable <B1-Motion> {dragit %W %x %y}
pack .c
*********************