Tkinter Scrollbar

Scrollbar helps user to scroll and view the entire content.
Scrollbar(parent window, options .. )
Scrollbar in Tkinter GUI

Tkinter Scrollbar and integrating it with text & Spinbox using different layouts with all options
import tkinter as tk
from tkinter import *
sb = tk.Scrollbar(my_w,cursor='hand1')
l1 = tk.Listbox(my_w,height=8,width=90,
	bg='yellow', yscrollcommand = sb.set )
for i in range(1, 40): # multiple lines added to Listbox
    l1.insert(END, "Line No : " + str(i))
sb.config( command = l1.yview )



In above code we used cursor='hand' to change the cursor shape when it is over the scrollbar. You can get a list of curshor shapes in our button widget.


Scrollbar orient option in Tkinter GUI
By default the option orient is 'vertical' , we can set it to horizontal to display the Scrollbar in horizontal direction.
sb = tk.Scrollbar(my_w,orient='horizontal')

Using Scrollbar with Listbox

We will use grid layout to place the widgets
Tkinter Listbox with Scrollbar using grid layout
import tkinter as tk
my_w = tk.Tk()
my_w.geometry("300x200")  # Size of the window 
l1=tk.Label(my_w,text='Listbox with Scroll bar')
sb = tk.Scrollbar(my_w)
sb.grid(row=2, column=2,  sticky='e')
l1 = tk.Listbox(my_w,height=2, yscrollcommand = sb.set)

for element in my_list: # adding elements to Listbox
sb.config( command = l1.yview )
my_w.mainloop()  # Keep the window open

Using Scrollbar with Text

We will use grid to place the widgets and one text box is used for inputs
Tkinter text with Scrollbar
import tkinter  as tk 
my_w = tk.Tk()

sb = tk.Scrollbar(my_w)
sb.grid(row=1, column=2,  sticky='w')

t1 = tk.Text(my_w, height=3, width=35) 

t1.insert(tk.END, my_str1)

sb.config( command = t1.yview )

Adding scrollbar to Treeview

Vertical Scrollbar for Treeview
Since Treeview is used to show tabular data, we may have to show more rows by allowing the user to scroll up or down by using scrollbar.
How Vertical scrollbar is added to Treeview while displaying MySQL records
OptionMenu Projects in Tkinter
Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net

    Post your comments , suggestion , error , requirements etc here

    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 All rights reserved worldwide Privacy Policy Disclaimer