Bartłomiej 'furas' Burek
furas.pl
# prywatne notatki - Python, Linux, Machine Learning, etc.

Tkinter: How to display Listbox with Scrollbar

It adds Listbox on left side and Scrollbar on right side.

Scrollbar uses command=listbox.yview to move Listbox content when Scrollbar is moved.

Listbox uses yscrollcommand=scrollbar.set to move Scrollbar when element in Listbox is added or removed or content is moved by key or mouse wheel.

import tkinter as tk

root = tk.Tk()

listbox = tk.Listbox(root)
listbox.grid(row=0, column=0, sticky="news")

scrollbar = tk.Scrollbar(root, orient='vertical', command=listbox.yview)
scrollbar.grid(row=0, column=1, sticky='ns')

listbox.config(yscrollcommand=scrollbar.set)

# add some values to listbox for scrolling
for i in range(50):
    listbox.insert('end', str(i))

root.mainloop()
Książki: python-dla-kazdego-podstawy-programowania python-wprowadzenie python-leksykon-kieszonkowy python-receptury python-programuj-szybko-i-wydajnie python-projekty-do-wykorzystania black-hat-python-jezyk-python-dla-hackerow-i-pentesterow efektywny-python-59-sposobow-na-lepszy-kod tdd-w-praktyce-niezawodny-kod-w-jezyku-python aplikacje-internetowe-z-django-najlepsze-receptury