Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

rectangle canvas as a scale

Status
Not open for further replies.

sl1200mk2

Technical User
Jun 7, 2005
39
FR
hi all
i would like to have a canvas who act like a scale
for example:
a rectangle is displayed
on entering with the mouse on a scrollregion, a text show a value -from (x) -to (x), growing when mouse go up, and decreasing when mouse go down.

how can i do that?
many thanks
nicolas
 
pack [canvas .c -width 100 -height 20 -bd 1 -relief solid] -side top
.c conf -scrollregion [.c bbox all]
bind .c <ButtonPress-1><Motion> { .c delete num ;.c create text 50 10 -text [.c canvasy %y] -tag num -justify center}

the problem with this code is:
i have to right click to stop the motion ....
i would like that if i drag up again, the counting start with the showed value (and not the position of the cursor in the window.....

 
someone gave me this code
package require Tk
namespace eval ::scale {
variable x 0
variable y

}

proc ::scale::start {input} {
variable y
set y [.c canvasy $input]
}

proc ::scale::motion {input} {
variable x
variable y
set new_y [.c canvasy $input]
set x [expr $x + ($y - $new_y) ]
.c delete num
.c create text 50 10 -text $x -tag num -justify center
set y $new_y
puts [winfo pointery .]

}

pack [canvas .c -width 100 -height 20 -bd 1 -relief solid] -side top
.c conf -scrollregion [.c bbox all]

bind .c <ButtonPress-1> [list ::scale::start %y]
bind .c <B1-Motion> [list ::scale::motion %y]

and it works as i want....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top