A scrollbar is a widget that is useful to scroll the text in another widget. For example, the text in Text, Canvas Frame or Listbox can be scrolled from top to bottom or left to right using scrollbars. There are two types of scrollbars. They are horizontal and vertical. The horizontal scrollbar is useful to view the text from left to right. The vertical scrollbar is useful to scroll the text from top to bottom.
Now let us see how we can create a scrollbar. To create a scrollbar we have to create a scrollbar class object as:
h = Scrollbar(root, orient='horizontal')
Here h represents the scrollbar object which is created as a child to root window. Here orient indicates horizontal for horizontal scrollbar and vertical indicates vertical scroll bars. Similarly to create a vertical scrollbar we can write:
v = Scrollbar(root, orient='horizontal')
On attaching the scrollbar to a widget like text box, list box, etc we then have to give add a command xview for horizontal scrollbar and yview for the vertical scrollbar.
h.config(command=t.xview) #for horizontal scrollbar v.config(command=t.yview) #for vertical scrollbar
Now let us look at the code for attaching a vertical and horizontal scrollbar to a Text Widget.
- Scrollable ListBox in Python-tkinter
- Tkinter Application to Switch Between Different Page Frames
- PyQt5 - Scrollable Label
- PyQt5 - Getting text of scrollable label
- PyQt5 Scrollable Label - Setting tool tip
- PyQt5 Scrollable Label – Getting tool tip duration
- Python | Program to extract frames using OpenCV
- PyQt5 Scrollable Label – Setting tool tip duration
- PyQt5 Scrollable Label - Retrieving tooltip text
- PyQt5 Scrollable Label – Setting tool tip duration to label part
- PyQt5 Scrollable Label - Getting tool tip text of the label part
- PyQt5 Scrollable Label – Getting tool tip duration of the label part
- PyQt5 Scrollable Label - Setting tool tip to the label part
- Hello World in Tkinter
- Python GUI - tkinter
- What are Widgets in Tkinter?
- Introduction to Tkinter
- Popup Menu in Tkinter
- Python: Age Calculator using Tkinter
- Loading Images in Tkinter using PIL
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.