itinneed
itinneed

Reputation: 153

Adding scrollbar to listbox in Tkinter

I'm running in circles on this one. I've checked a dozen posts and I'm not seeing what I've done wrong. Here's the code:

from tkinter import *
class Frame1(Frame):
    def __init__(self, master):
        #super().__init__()

        self.lblTitle = Label(master, text="Ticket List")
        self.lblTitle.grid(row=0, column=0)
        self.listTickets = Listbox(master, width=20, height=20, font=("Arial", 11))
        self.listTickets.grid(row=1, column=0)
        self.scrollbar = Scrollbar(master, orient=VERTICAL)
        self.scrollbar.grid(row=1, column=1)
        self.listTickets.config(yscrollcommand=self.scrollbar.set)
        self.scrollbar.config(command=self.listTickets.yview)

        for i in range(1000):
            self.listTickets.insert(END, str(i))


window = Tk()
window.title("Ticket System")
frame = Frame1(window)

window.mainloop()

Where have I gone wrong? This just creates a tiny up/down arrow and not a true scrollbar.

enter image description here

Upvotes: 0

Views: 151

Answers (1)

Saad
Saad

Reputation: 3430

You have to use sticky argument in the grid function of scrollbar to extend the scrollbar in north and south. You can further read about it here.

self.scrollbar.grid(row=1, column=1, sticky="ns")

Upvotes: 3

Related Questions