The Wayback Machine - https://web.archive.org/web/20240912002856/https://www.geeksforgeeks.org/scrollable-frames-in-tkinter/
Open In App

Scrollable Frames in Tkinter

Last Updated : 04 Mar, 2021
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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='vertical')

On attaching the scrollbar to a widget like text box, list box, etc we then have to 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. 

Python3




# Python Program to make a scrollable frame
# using Tkinter
  
from tkinter import *
  
class ScrollBar:
     
    # constructor
    def __init__(self):
         
        # create root window
        root = Tk()
  
        # create a horizontal scrollbar by
        # setting orient to horizontal
        h = Scrollbar(root, orient = 'horizontal')
  
        # attach Scrollbar to root window at
        # the bootom
        h.pack(side = BOTTOM, fill = X)
  
        # create a vertical scrollbar-no need
        # to write orient as it is by
        # default vertical
        v = Scrollbar(root)
  
        # attach Scrollbar to root window on
        # the side
        v.pack(side = RIGHT, fill = Y)
          
  
        # create a Text widget with 15 chars
        # width and 15 lines height
        # here xscrollcomannd is used to attach Text
        # widget to the horizontal scrollbar
        # here yscrollcomannd is used to attach Text
        # widget to the vertical scrollbar
        t = Text(root, width = 15, height = 15, wrap = NONE,
                 xscrollcommand = h.set,
                 yscrollcommand = v.set)
  
        # insert some text into the text widget
        for i in range(20):
            t.insert(END,"this is some text\n")
  
        # attach Text widget to root window at top
        t.pack(side=TOP, fill=X)
  
        # here command represents the method to
        # be executed xview is executed on
        # object 't' Here t may represent any
        # widget
        h.config(command=t.xview)
  
        # here command represents the method to
        # be executed yview is executed on
        # object 't' Here t may represent any
        # widget
        v.config(command=t.yview)
  
        # the root window handles the mouse
        # click event
        root.mainloop()
 
# create an object to Scrollbar class
s = ScrollBar()
        


Output:



Previous Article
Next Article

Similar Reads

Tkinter Application to Switch Between Different Page Frames
Prerequisites: Python GUI – tkinter Sometimes it happens that we need to create an application with several pops up dialog boxes, i.e Page Frames. Here is a step by step process to create multiple Tkinter Page Frames and link them! This can be used as a boilerplate for more complex python GUI applications like creating interfaces for Virtual Labora
6 min read
Create Multiple frames with Grid manager using Tkinter
Prerequisites: Tkinter Tkinter can support the creation of more than one widget in the same frame. Not just this it also supports a mechanism to align them relative to each other. One of the easiest ways of aligning the different widgets in the Tkinter is through grid manager. Apart from aligning various widgets, the grid manager can also be used f
2 min read
How to Display Images within Tkinter Frames
Tkinter is a Python module used to create Graphical User Interface (GUI) applications. Tkinter has many widgets such as Button, Label, Text, Entry, Frame, Checkbox and more that make it easy and quick to develop desktop applications. How to Insert Image inside Frame in Tkinter?To insert an image inside a frame is the same as inserting an image in T
1 min read
Scrollable ListBox in Python-tkinter
Tkinter is the standard GUI library for Python. Tkinter in Python comes with a lot of good widgets. Widgets are standard GUI elements, and the Listbox, Scrollbar will also come under this Widgets. Note: For more information, refer to Python GUI – tkinter Listbox The ListBox widget is used to display different types of items. These items must be of
2 min read
Difference Between The Widgets Of Tkinter And Tkinter.Ttk In Python
Python offers a variety of GUI (Graphical User Interface) frameworks to develop desktop applications. Among these, Tkinter is the standard Python interface to the Tk GUI toolkit. Tkinter also includes the 'ttk' module, which enhances the visual appeal and functionality of the applications. In this article, we will cover the differences, providing a
4 min read
Find Columns Shared By Two Data Frames
Pandas is the open-source Python library used for Data analysis and manipulation. It is fast, powerful, flexible, and easy to use. In this article, we will discuss how to find columns that are common between two Data Frames. Below is the different approach that can be used to find common columns. Method 1: Using Numpy intersect1d method In this exa
2 min read
MoviePy – Iterating frames of Video File Clip
In this article we will see how we can iterate frames of the video file clip in MoviePy. MoviePy is a Python module for video editing, which can be used for basic operations on videos and GIF’s. A video is basically combination of lots of frame for each time there is a specific frame, in order to get the frame at given time we use get_frame method.
2 min read
How to handle Frames/iFrames in Selenium with Python
Selenium is an effective device for controlling an internet browser through the program. It is purposeful for all browsers, works on all fundamental OS and its scripts are written in numerous languages i.e Python, Java, C#, etc, we can be running with Python. HTML outlines are utilized to isolate your program window into numerous segments where eac
2 min read
Extract Video Frames from Webcam and Save to Images using Python
There are two libraries you can use: OpenCV and ImageIO. Which one to choose is situation-dependent and it is usually best to use the one you are already more familiar with. If you are new to both then ImageIO is easier to learn, so it could be a good starting point. Whichever one you choose, you can find examples for both below: ImageIOInstallatio
2 min read
Save frames of live video with timestamps - Python OpenCV
Images are very important data nowadays from which we can obtain a lot of information which will helpful for analysis. Sometimes data to be processed can be in the form of video. To process this kind of data we have to read video extract frames and save them as images. Security camera videos we have seen that there is a timestamp and date at top of
3 min read
PyQt5 - Scrollable Label
In this article we will see how we can create a scroll-able label, by default when we create a label all the text is in the single line and if length of text is greater than label, extra text didn't show, although with the help of setWordWrap method we can create a multi-line label but still if the text exceeds it will not show in the label.In orde
3 min read
PyQt5 - Getting text of scrollable label
In this article we will see how we can get the text of the scroll-able label, we can create a scroll-able label with the help of making new class which inherits scroll area class but the problem arises the new class can only set the text we can't get the text as it is scroll-able label class object not the normal label object. In order to retrieve
3 min read
PyQt5 Scrollable Label - Setting tool tip
In this article we will see how we can set tooltip to the scroll-able label. By default when we create a label all the text is in the single line and if length of text is greater than label, extra text didn’t show, although with the help of setWordWrap method we can create a multi-line label but still if the text exceeds it will not show in the lab
3 min read
PyQt5 Scrollable Label - Setting tool tip to the label part
In this article we will see how we can set tool tip to the label part of scroll label, when know we can make scrollable label with the help of inheriting a scroll class and making label in it, but when we set tool tip to the class object tool tip is set to the whole widget i.e label and the scroll bar as well. In order to add tool tip the label par
3 min read
PyQt5 Scrollable Label - Getting tool tip text of the label part
In this article we will see how we can get tool tip text of the label part of scrollable label, when know we can make scrollable label with the help of inheriting a scroll class and making label in it, but when we set tool tip to the class object tooltip is set to the whole widget i.e label and the scroll bar as well. In order to add tool tip the l
3 min read
PyQt5 Scrollable Label - Retrieving tooltip text
In this article we will see how we can get tooltip text of the scroll label, when know we can make scrollable label with the help of inheriting a scroll class and making label in it. Scroll Label is basically two widgets combined together scroll area act as a base widget and label act as a component of this class. Steps for implementations - 1. Cre
3 min read
PyQt5 Scrollable Label – Setting tool tip duration
In this article we will see how we can set tooltip duration to the scroll-able label. By default when we create a label all the text is in the single line and if length of text is greater than label, extra text didn’t show, although with the help of setWordWrap method we can create a multi-line label but still if the text exceeds it will not show i
3 min read
PyQt5 Scrollable Label – Getting tool tip duration
In this article we will see how we can get the tooltip duration of the scroll label, scrollable label is a label which has a scrolling feature to it. Steps for implementations - 1. Create a new class which inherits QScrollArea 2. Inside the class create vertical layout 3. Create a label and make it multi-line and add it to the layout 5. Over-ride t
3 min read
PyQt5 Scrollable Label – Setting tool tip duration to label part
In this article we will see how we can set tooltip duration to the label part of scroll label, when know we can make scrollable label with the help of inheriting a scroll class and making label in it, but when we set tooltip to the class object tooltip is set to the whole widget i.e label and the scroll bar as well. In order to add tooltip and its
3 min read
PyQt5 Scrollable Label – Getting tool tip duration of the label part
In this article we will see how we can get the tooltip duration of the label part of scrollable label, when know we can make scrollable label with the help of inheriting a scroll class and making label in it, but when we set tooltip to the class object tooltip is set to the whole widget i.e label and the scroll bar as well. In order to get tooltip
3 min read
Python | askopenfile() function in Tkinter
While working with GUI one may need to open files and read data from it or may require to write data in that particular file. One can achieve this with the help of open() function (python built-in) but one may not be able to select any required file unless provides a path to that particular file in code. With the help of GUI, you may not require to
2 min read
Python | Binding function in Tkinter
Tkinter is a GUI (Graphical User Interface) module that is widely used in desktop applications. It comes along with the Python, but you can also install it externally with the help of pip command. It provides a variety of Widget classes and functions with the help of which one can make our GUI more attractive and user-friendly in terms of both look
3 min read
Make Notepad using Tkinter
Let's see how to create a simple notepad in Python using Tkinter. This notepad GUI will consist of various menu like file and edit, using which all functionalities like saving the file, opening a file, editing, cut and paste can be done. Now for creating this notepad, Python 3 and Tkinter should already be installed in your system. You can download
6 min read
Facts App Using Tkinter module
This is an app that will provide us with Facts. With Python, we can make things very easy. We have a very amazing library so that we can do it. We just need two of the libraries and if we just combine the concept, we will be able to make a new thing. We just have to use tkinter and randfacts to do this so. Module RequiredTkinter: The tkinter packag
2 min read
Color game using Tkinter in Python
TKinter is widely used for developing GUI applications. Along with applications, we can also use Tkinter GUI to develop games. Let's try to make a game using Tkinter. In this game player has to enter color of the word that appears on the screen and hence the score increases by one, the total time to play this game is 30 seconds. Colors used in this
4 min read
Python | Message Encode-Decode using Tkinter
Prerequisite : Basics of TkinterPython offers multiple options for developing GUI (Graphical User Interface). Out of all the GUI methods, tkinter is most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with tkinter outputs the fastest and easiest way to create the GUI applications. Python pr
5 min read
Python - Tkinter askquestion Dialog
In Python, There Are Several Libraries for Graphical User Interface. Tkinter is one of them that is most useful. It is a standard interface. Tkinter is easy to use and provides several functions for building efficient applications. In Every Application, we need some Message to Display like "Do You Want To Close " or showing any warning or Something
4 min read
Simple registration form using Python Tkinter
Prerequisites: Tkinter Introduction, openpyxl module.Python provides the Tkinter toolkit to develop GUI applications. Now, it’s upto the imagination or necessity of developer, what he/she want to develop using this toolkit. Let's make a simple information form GUI application using Tkinter. In this application, User has to fill up the required info
5 min read
Python | Simple GUI calculator using Tkinter
Prerequisite: Tkinter Introduction, lambda function Python offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with Tkinter outputs the fastest and easiest way to create GUI a
6 min read
Python | Distance-time GUI calculator using Tkinter
Prerequisites : Introduction to Tkinter | Using google distance matrix API Python offers multiple options for developing GUI (Graphical User Interface). Out of all the GUI methods, tkinter is most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with tkinter outputs the fastest and easiest wa
7 min read
Article Tags :
Practice Tags :