Skip to content

Instantly share code, notes, and snippets.

@jxc876
Created June 18, 2025 14:11
Show Gist options
  • Select an option

  • Save jxc876/4b8123ab39188e9e65d28da4527f435a to your computer and use it in GitHub Desktop.

Select an option

Save jxc876/4b8123ab39188e9e65d28da4527f435a to your computer and use it in GitHub Desktop.
Python TK Scrollbar

Creates a Table with 500 rows which can scroll.

image

image

For the scrolling part just add a scrollbar:

    # Add vertical scrollbar
    scrollbar = ttk.Scrollbar(root, orient="vertical", command=tree.yview)
    tree.configure(yscroll=scrollbar.set)
import tkinter as tk
from tkinter import ttk
if __name__ == "__main__":
# Create main window
root = tk.Tk()
root.title("Simple Table")
root.geometry("400x400")
# Create Treeview widget (table)
columns = ("ID", "Name")
tree = ttk.Treeview(root, columns=columns, show="headings")
# Define headings
tree.heading("ID", text="ID")
tree.heading("Name", text="Name")
# Insert 500 rows of sample data
for i in range(1, 501):
tree.insert("", "end", values=(i, f"Item {i}"))
# Add vertical scrollbar
scrollbar = ttk.Scrollbar(root, orient="vertical", command=tree.yview)
tree.configure(yscroll=scrollbar.set)
# Layout
tree.pack(side="left", fill="both", expand=True)
scrollbar.pack(side="right", fill="y")
# Run the app
root.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment