Silentkiller
Technical User
Hi,
Can anyone enlighten me on how can i draw a straight line across the image i have called. Acutally i have tried to combine two code that is
#Calling out the Image
{
set w .image1
catch {destroy $w}
toplevel $w
wm title $w "Image Display"
wm iconname $w "Image1"
catch {image delete image1}
image create photo image1 -file [file join demos images y:/Filename/PGM/eye.pgm]
button .image1.edit -text Line -command {draw_line} -underline 0
pack .image1.edit -side bottom
label $w.l1 -image image1 -bd 1 -relief sunken
pack $w.l1 -side top -padx 10m -pady 10m
}
Drawing the line :
bind .image1 <ButtonPress-1> {line_start %W %x %y}
bind .image1 <B1-Motion> {line_drag %W %x %y}
bind .image1 <ButtonRelease-1> {line_end %W %x %y}
# The size of the grid divisions
set GRIDSIZE 20
bind .image1 <Control-ButtonPress-1> { }
bind .image1 <Control-B1-Motion> { }
bind .image1 <Control-ButtonRelease-1> { }
proc line_start {canv x y} {
global GRIDSIZE
global line
set line(x0) [expr {round($x/$GRIDSIZE)*$GRIDSIZE}]
set line(y0) [expr {round($y/$GRIDSIZE)*$GRIDSIZE}]
set line(id) [$canv cget line $line(x0) $line(y0) $line(x0) $line(y0)]
$canv bind $line(id) <Control-ButtonPress-1> [list line_move_start $canv $line(id) %x %y]
$canv bind $line(id) <Control-B1-Motion> [list line_move_drag $canv $line(id) %x %y]
$canv bind $line(id) <Control-ButtonRelease-1> [list line_move_end $canv $line(id) %x %y]
}
proc line_drag {canv x y} {
global line
$canv coords $line(id) $line(x0) $line(y0) $x $y
}
proc line_end {canv x y} {
global GRIDSIZE
global line
# Make final vertex on the nearest grid point
set x [expr {round($x/$GRIDSIZE)*$GRIDSIZE}]
set y [expr {round($y/$GRIDSIZE)*$GRIDSIZE}]
line_drag $canv $x $y
$canv itemconfigure $line(id) -fill blue
}
proc line_move_start {canv id x y} {
global line
set line(xs) $x
set line(ys) $y
$canv raise $id
$canv itemconfigure $id -stipple gray50
}
proc line_move_drag {canv id x y} {
global line
$canv move $id [expr {$x-$rect(xs)}] [expr {$y-$line(ys)}]
set line(xs) $x
set line(ys) $y
}
proc line_move_end {canv id x y} {
global GRIDSIZE
line_move_drag $canv $id $x $y
foreach {x0 y0 x1 y1} [$canv coords $id] {break}
$canv move $id [expr {(round($x0/$GRIDSIZE)*$GRIDSIZE)-$x0}] [expr {(round($y0/$GRIDSIZE)*$GRIDSIZE)-$y0}]
$canv itemconfigure $id -stipple ""
}
But i always encounter this error:
bad option "create": must be cget or configure
what is wrong with my program
Can anyone enlighten me on how can i draw a straight line across the image i have called. Acutally i have tried to combine two code that is
#Calling out the Image
{
set w .image1
catch {destroy $w}
toplevel $w
wm title $w "Image Display"
wm iconname $w "Image1"
catch {image delete image1}
image create photo image1 -file [file join demos images y:/Filename/PGM/eye.pgm]
button .image1.edit -text Line -command {draw_line} -underline 0
pack .image1.edit -side bottom
label $w.l1 -image image1 -bd 1 -relief sunken
pack $w.l1 -side top -padx 10m -pady 10m
}
Drawing the line :
bind .image1 <ButtonPress-1> {line_start %W %x %y}
bind .image1 <B1-Motion> {line_drag %W %x %y}
bind .image1 <ButtonRelease-1> {line_end %W %x %y}
# The size of the grid divisions
set GRIDSIZE 20
bind .image1 <Control-ButtonPress-1> { }
bind .image1 <Control-B1-Motion> { }
bind .image1 <Control-ButtonRelease-1> { }
proc line_start {canv x y} {
global GRIDSIZE
global line
set line(x0) [expr {round($x/$GRIDSIZE)*$GRIDSIZE}]
set line(y0) [expr {round($y/$GRIDSIZE)*$GRIDSIZE}]
set line(id) [$canv cget line $line(x0) $line(y0) $line(x0) $line(y0)]
$canv bind $line(id) <Control-ButtonPress-1> [list line_move_start $canv $line(id) %x %y]
$canv bind $line(id) <Control-B1-Motion> [list line_move_drag $canv $line(id) %x %y]
$canv bind $line(id) <Control-ButtonRelease-1> [list line_move_end $canv $line(id) %x %y]
}
proc line_drag {canv x y} {
global line
$canv coords $line(id) $line(x0) $line(y0) $x $y
}
proc line_end {canv x y} {
global GRIDSIZE
global line
# Make final vertex on the nearest grid point
set x [expr {round($x/$GRIDSIZE)*$GRIDSIZE}]
set y [expr {round($y/$GRIDSIZE)*$GRIDSIZE}]
line_drag $canv $x $y
$canv itemconfigure $line(id) -fill blue
}
proc line_move_start {canv id x y} {
global line
set line(xs) $x
set line(ys) $y
$canv raise $id
$canv itemconfigure $id -stipple gray50
}
proc line_move_drag {canv id x y} {
global line
$canv move $id [expr {$x-$rect(xs)}] [expr {$y-$line(ys)}]
set line(xs) $x
set line(ys) $y
}
proc line_move_end {canv id x y} {
global GRIDSIZE
line_move_drag $canv $id $x $y
foreach {x0 y0 x1 y1} [$canv coords $id] {break}
$canv move $id [expr {(round($x0/$GRIDSIZE)*$GRIDSIZE)-$x0}] [expr {(round($y0/$GRIDSIZE)*$GRIDSIZE)-$y0}]
$canv itemconfigure $id -stipple ""
}
But i always encounter this error:
bad option "create": must be cget or configure
what is wrong with my program