Introduction to Programming using Python 1st Edition

Published by Pearson
ISBN 10: 0132747189
ISBN 13: 978-0-13274-718-9

Chapter 9 - GUI Programming using Tkinter - Section 9.13 - Scrollbars - Check Point - MyProgrammingLab - Page 301: 9.40

Answer

To associate a scrollbar with a view in Tkinter, you need to use the set method of the scrollbar and pass it the values of the view you want it to control.

Work Step by Step

For example, if you have a canvas widget named canvas and a scrollbar widget named scrollbar, you can associate the scrollbar with the canvas like this: scrollbar.config(command=canvas.yview) canvas.config(yscrollcommand=scrollbar.set) In this example, the command option of the scrollbar is set to the yview method of the canvas, and the yscrollcommand option of the canvas is set to the set method of the scrollbar. This sets up a bidirectional relationship between the canvas and the scrollbar, so that when the scrollbar is used to scroll the canvas, the canvas will automatically update the position of the scrollbar, and vice versa.
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.