tkinter scroll in python

To add a scrollbar to a tkinter widget like a Listbox or a Text widget in Python using the tkinter library, you can follow the below steps:

main.py
import tkinter as tk

root = tk.Tk()

# Create a scrollbar
scrollbar = tk.Scrollbar(root)
scrollbar.pack(side=tk.RIGHT, fill=tk.Y)

# Create a Text widget
text = tk.Text(root, yscrollcommand=scrollbar.set)
text.pack()

# Configure the scrollbar to scroll the Text widget
scrollbar.config(command=text.yview)

root.mainloop()
325 chars
17 lines

In this code snippet, a Scrollbar is created and attached to a Text widget using the yscrollcommand parameter. The configuration of the scrollbar is set to scroll the Text widget along the y-axis.

related categories

gistlibby LogSnag