In this post we will learn about the Scrollbars widget in Tkinter, Scrollbars is actually an independent widget which we will learn how to integrate it with the text widget we saw in our earlier post. Lets get started,
IN[1]
import tkinter as tk
from tkinter import ttk
try :
from ctypes import windll
windll.shcore.SetProcessDpiAwareness(1)
except :
pass
root = tk.Tk()
root.geometry("600x400")
root.resizable(False, False)
root.title("Scrollbars in Tkinter")
root.grid_rowconfigure(0, weight = 1)
root.grid_columnconfigure(0, weight = 1)
text = tk.Text(root, height = 8)
text.grid(row = 0, column = 0, sticky = "ew")
text.insert("1.0", "This is a sample text")
text_scroll = ttk.Scrollbar(root, orient = "vertical", command = text.yview)
text_scroll.grid(row = 0, column = 1, sticky = "ns")
root.mainloop()
OUT[1]
1
IN[2]
import tkinter as tk
from tkinter import ttk
try :
from ctypes import windll
windll.shcore.SetProcessDpiAwareness(1)
except :
pass
root = tk.Tk()
root.geometry("600x400")
root.resizable(False, False)
root.title("Scrollbars in Tkinter")
root.grid_rowconfigure(0, weight = 1)
root.grid_columnconfigure(0, weight = 1)
text = tk.Text(root, height = 8)
text.grid(row = 0, column = 0, sticky = "ew")
text.insert("1.0", "This is a sample text")
text_scroll = ttk.Scrollbar(root, orient = "vertical", command = text.yview)
text_scroll.grid(row = 0, column = 1, sticky = "ns")
text["yscrollcommand"] = text_scroll.set
root.mainloop()
OUT[2]
I