Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Tutorials listed in this section have not been reviewed nor are affliated by Code Forum. It is the sole responsbility of the authour to properly maintain and ensure information is accurate.

Python Tkinter listbox with scrollbar

A Basic listbox with scrollbar

Python:
# Do the imports
import tkinter as tk
from tkinter import font

# Create the window
root = tk.Tk()
root.title('Tkinter listbox and scrollbar')
root.minsize(400,400)

# get available fonts
fonts = font.families()

# Create tkinter listbox widget
listbox = tk.Listbox(root)
listbox.pack(side='left', fill='both', expand=True)

# Create the scrollbar
scrollbar = tk.Scrollbar(root)
scrollbar.pack(side='right', fill='y')

# Configure the scrollbar and listbox
scrollbar.configure(command=listbox.yview)
listbox.configure(yscrollcommand=scrollbar.set)

# Insert data into the listbox
for font in fonts:
    listbox.insert('end', f' {font}')

root.mainloop()
 
Back
Top Bottom