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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scrolling Canvas Problems

Status
Not open for further replies.

SmallProgram

Programmer
Feb 6, 2002
42
IN
Hello Friends,
This is Mallik again.
I have a problem again with the scrolling of Canvas.
When Iam adding a text Box on the canvas Iam able to scroll the Canvas but the problem is that TextBox that is on the canvas is remaimng there.
Can You suggest Me a n answer for this Question
Thanks In Advance.
Mallik.
Programmer,Amatuer
 
Without seeing your script, it's hard to say what's happening. Are you using the "-scrollregion" option? How are you packing the textbox? Bob Rashkin
rrashkin@csc.com
 
Sorry for the vague question.
Iam Using the -scrollregion.
But still Iam not able to scroll the canvas.In fact Iam not packing it. Iam placing it.
Iam not placing the textwidget on the canvas on the fly by using the mouse events.
Mallik. Programmer,Amatuer
 
Sorry a mistake in my earlier letter.I said "Iam not placing" it but it should be "placing it". Programmer,Amatuer
 
When you use the canvas as a widget manager, the widgets displayed on the canvas shouldn't be packed, gridded, or placed. Instead, you need to use the canvas's create window operation to manage the widget.

Here's a simple example that I whipped up for someone else demonstrating how to use the canvas widget as a scrollable manager. (Please excuse the bad line breaks, but there's a few too many lines of code here for me to want to properly wrap all of them for this forum.)

Code:
# Create a toplevel window for displaying a bunch of
# checkbuttons.  We'll display this on demand from the
# main window.

toplevel .dialog

canvas .dialog.c  -height 100 -width 50     -yscrollcommand {.dialog.sb set}
scrollbar .dialog.sb -orient vertical -command {.dialog.c yview}

# Create our frame to hold all of our checkbuttons

frame .dialog.c.buttons

# Create a bunch of checkbuttons and pack them into the frame

for {set i 1} {$i <=10 } {incr i} {
    checkbutton .dialog.c.buttons.$i -text &quot;$i&quot; -variable c($i)
    pack .dialog.c.buttons.$i -anchor w -padx 2 -pady 1
}

# Tell the canvas to display the frame, anchoring the
# upper-left hand corner of the frame in the upper-left
# hand corner of the canvas

.dialog.c create window 0 0 -anchor nw -window .dialog.c.buttons

button .dialog.close -text &quot;Close window&quot; -command {
    wm withdraw .dialog
}

# Use grid to display the canvas, the scrollbar, and the
# close button in the toplevel window. Handle resizing properly.

grid .dialog.c -row 0 -column 0 -sticky nsew -pady 4 -padx 2
grid .dialog.sb -row 0 -column 1 -sticky ns -pady 4 -padx 2
grid .dialog.close -row 1 -column 0 -columnspan 2 -pady 2
grid columnconfigure .dialog 0 -weight 1
grid rowconfigure .dialog 0 -weight 1

# Detect <Configure> events on the frame to detect when
# it is first displayed and any time is is resized.
# In either case, recompute the visible bounds of the
# canvas and update its -scrollregion attribute.

bind .dialog.c.buttons <Configure> {
    .dialog.c configure -scrollregion [.dialog.c bbox all]
}

# Finish the setup of the toplevel dialog window

wm title .dialog &quot;Checkbuttons Galore!&quot;
wm withdraw .dialog

# Create our main window interface

button .popup -text &quot;Settings...&quot; -command {
    wm deiconify .dialog
}

button .exit -text &quot;Quit&quot; -command { exit }

pack .popup .exit -padx 4 -pady 4
- Ken Jones, President
Avia Training and Consulting
866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
Thank you Mr.Ken I didnot even think of this Situation even.
Thank You.
Mallik. Programmer,Amatuer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top