Search code examples
pythontkinterslider

Trouble with scrollbar tkinter python


How i can fix this trouble? In this scrollbar works only arrows.Scrollbar I have 500 + strings in my listbox. I used insert to add elements to listbox

I think i have problems with config but i don't know how to fix it

connect listbox and slider

def show_popup():
    # popup settings
    popup = tk.Toplevel(window)
    popup.title("Add/Remove")
    popup.geometry("400x500")

    # listbox of keys and values
    list_frame = ttk.Frame(popup, height=15)
    list_frame.pack(side="top")

    # add slider
    scrollbar = tk.Scrollbar(list_frame, orient="vertical")
    scrollbar.grid(row=0, column=3)

    # listbox
    global listbox
    listbox = tk.Listbox(list_frame, width=60, height=15)
    listbox.grid(row=0, column=0, columnspan=3)

    # connect listbox and slider
    scrollbar.config(command=listbox.yview)
    listbox.config(yscrollcommand=scrollbar.set)

    # display pairs
    display_json_data(original_data)

    # add function
    add_frame = ttk.Frame(popup)
    add_frame.pack(side="top")
    add_title = ttk.Label(popup, text="Add function")
    add_title.pack(padx=20, pady=20)

    # Close toplevel window
    close_button = ttk.Button(
        popup, text="Close window", command=popup.destroy)
    close_button.pack(side="bottom")

Solution

  • Configure your scrollbar so it takes up all the height of its row:

    ...
    # add slider
        scrollbar = tk.Scrollbar(list_frame, orient="vertical")
        scrollbar.grid(row=0, column=3, sticky="ns")
    ...