Line | |
---|
1 | # scroll_canvas.tcl --
|
---|
2 | # Experiment with scrolling canvas items selectively
|
---|
3 | #
|
---|
4 |
|
---|
5 | canvas .c -width 400 -height 200
|
---|
6 | scrollbar .y -command scrollc
|
---|
7 |
|
---|
8 | grid .c .y -sticky news
|
---|
9 |
|
---|
10 | .c create text 200 10 -text "Title"
|
---|
11 | .c lower [.c create rectangle 0 0 400 30 -fill white -outline {} ]
|
---|
12 |
|
---|
13 | .c lower [.c create text 10 50 -text "Item" -anchor w -tag Move]
|
---|
14 | .c lower [.c create polygon 80 50 140 50 140 350 -fill green -tag Move]
|
---|
15 |
|
---|
16 | # Set the parameters for the scrollbar
|
---|
17 | .y set 0.0 0.5
|
---|
18 | set currentPos 0.0
|
---|
19 |
|
---|
20 | proc scrollc {operation number {unit ""}} {
|
---|
21 | # Ignore scroll operation
|
---|
22 | if { $operation == "moveto" } {
|
---|
23 | set dely [expr {400*($::currentPos-$number)}]
|
---|
24 | set ::currentPos $number
|
---|
25 | .c move Move 0 $dely
|
---|
26 | }
|
---|
27 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.