Scrollbar dùng cuộn văn bản. Có thanh ngang và dọc. Độ dài thay đổi theo nội dung. Tùy chỉnh style bằng ttk.Scrollbar và ttk.Style().
Ví dụ
# Import thư viện
from tkinter import *
from tkinter import ttk
# Tạo khung
win = Tk()
win.geometry("700x250")
style = ttk.Style()
style.theme_use('classic')
style.configure("Vertical.TScrollbar", background="green", bordercolor="red", arrowcolor="white")
# Thanh cuộn dọc
scrollbar = ttk.Scrollbar(win, orient='vertical')
scrollbar.pack(side=RIGHT, fill=BOTH)
# Text widget
text = Text(win, width=15, height=15, wrap=CHAR, yscrollcommand=scrollbar.set)
for i in range(1000):
text.insert(END, i)
text.pack(side=TOP, fill=X)
scrollbar.config(command=text.yview)
win.mainloop()Kết quả
Text widget với thanh cuộn dọc tùy chỉnh theme classic, màu xanh lá, viền đỏ, mũi tên trắng.
