CustomTkinter icon indicating copy to clipboard operation
CustomTkinter copied to clipboard

question: Is there a better way to create a scrollable frame?

Open clxakz opened this issue 2 years ago • 3 comments

I have tried using canvas and it kind of worked but the canvas itself is white and has no round corners and the frame containing all of the widgets to be scrolled is not properly scaling to fit the whole canvas and only scales to the size of the widgets. is there a better way of implementing a vertical scrollbar to a frame?

This is an example of using canvas, i have tried my best to make the canvas look better

import customtkinter

root = customtkinter.CTk()
root.title("Scrollable frame")
root.geometry("500x400")

# Main Frame
main_frame = customtkinter.CTkFrame(root)
main_frame.pack(fill="both", expand=True)

# Canvas
my_canvas = customtkinter.CTkCanvas(main_frame)
my_canvas.pack(side="left", fill="both", expand=True)

# Scrollbar
my_scrollbar = customtkinter.CTkScrollbar(
    main_frame, orientation="vertical", command=my_canvas.yview
)
my_scrollbar.pack(side="right", fill="y")

# Configure the canvas
my_canvas.configure(
    yscrollcommand=my_scrollbar.set, background="#2e2e2e", border=False, borderwidth=0
)
my_canvas.bind(
    "<Configure>", lambda e: my_canvas.configure(scrollregion=my_canvas.bbox("all"))
)

# New frame inside canvas
inner_frame = customtkinter.CTkFrame(my_canvas)

# Add new frame into a windows in the canvas
my_canvas.create_window((0, 0), window=inner_frame, anchor="nw")

# Populate frame with buttons
for x in range(11):
    my_button = customtkinter.CTkButton(inner_frame, text=f"Button {x}")
    my_button.pack(padx=15, pady=15)

root.mainloop()

This is what it looks like..

image

clxakz avatar Dec 11 '22 16:12 clxakz

same issue faced, white border comes without giving any request also when scrolls it passes through the white border line

anuraj3303 avatar Dec 14 '22 08:12 anuraj3303

Thats my solution. Use it like another one ctk widget. Dont forget watch the Example in module.

from CTkScrollFrame import CTkScrollFrame

https://github.com/Priboy313/my-tkinter-customtkinter-modules/blob/main/CTkScrollFrame.py

Priboy313 avatar Jan 06 '23 15:01 Priboy313

I've used a version of this https://gist.github.com/JackTheEngineer/81df334f3dcff09fd19e4169dd560c59 works like a charm after you replace the tk imports with ctk

infinitel8p avatar Jan 10 '23 07:01 infinitel8p