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!

Scrollable Frame on Canvas Overlaps Scrollbar 2

Status
Not open for further replies.

SNESWhiz

Programmer
Jun 25, 2002
3
US
After looking through this forum, I found the code I needed to create a scrollable frame, using a canvas.

When I execute the code, though, the text from the frame overlaps the scrollbar. I can scroll back and forth, but clicking the areas where the text is above the scrollbar does nothing, since I am clicking on the text, and not the scrollbar.

A screenshot of the problem can be found at
 
Could you post the portion of the code that you use to construct and manipulate the scrolled frame? I've got a couple of ideas what might be going on, but it's difficult to pinpoint the problem without more information. Thanks. - Ken Jones, President
Avia Training and Consulting
866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
Here it is:

Code:
frame .dataarea
canvas .outputcanvas -xscrollcommand ".xscroll set" -yscrollcommand ".yscroll set"
scrollbar .xscroll -orient horizontal -command ".outputcanvas xview"
scrollbar .yscroll -orient vertical -command ".outputcanvas yview"

.outputcanvas create window 0 0 -anchor nw -window .dataarea
grid .outputcanvas - .yscroll -sticky news -pady 4 -padx 2
grid .xscroll - x -sticky news
grid rowconfigure . 0 -weight 1
grid columnconfigure . 0 -weight 1

bind .dataarea <Configure> {
    .outputcanvas configure -scrollregion [.outputcanvas bbox all]
}

label .l -text &quot;qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnm&quot;

pack .l -in .dataarea
 
Okay, got it. To properly use the canvas as a manager widget, you need to create the managed widgets as children of the canvas. So in your case, you should create your frame widget after creating the canvas, and give it a hierarchical name reflecting that it's a child of the canvas. For example:

Code:
frame .outputcanvas.dataarea

In this case, &quot;.outputcanvas.dataarea&quot; is the full name of the frame widget, and must be used everywhere that you refer to it. For example:

Code:
bind .outputcanvas.dataarea <Configure> { # ... }

Because these hierarchical names can end up being quite long, many people like to store the name in a variable for more convenient use later on. For example:

Code:
set data [frame .outputcanvas.dataarea]
bind $data <Configure> { # ... }

Then for the widgets that you create within the frame, give them hierarchical names as well, to reflect that they are managed by the frame. Then you won't need the pack -in option, as Tk automatically handles the management of hierarchically-named children. For example:

Code:
label .outputcanvas.dataarea.l     -text &quot;1234567890123456789012345678901234567890&quot;
pack .outputcanvas.dataarea.l -anchor w

From experimentation, I've determined that you must follow both of these recommendations for the scrolled frame to work correctly. Either not creating the frame as a child of the canvas or not creating the label as a child of the frame is enough for the label to overlap the scrollbars. - Ken Jones, President
Avia Training and Consulting
866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top