CustomTkinter – Vertical scrollable frame next to non-scrollable frame

I have a CustomTkinter app with an horizontal CTkScrollableFrame. Inside this frame, I have two frames:

  1. On the left, a CTkFrame, non-scrollable, here in blue, containing a smaller CTkFrame` (or any widgets), here in teal.
  2. On the right, a vertical CTkScrollableFrame, here in red, containing two more CTkFrame (or any widgets), here in orange and yellow.

The horizontal CTkScrollableFrame is expanding in the full window (vertical and horizontal), as wanted.
The vertical CTkScrollableFrame is not expanding in the complete space left in the window (horizontal).

How can I get the following result?

EDIT:

Based on the code from Demonstrate a CustomTkinker scrollable and clickable grid, I tried another solution, see “NEW MWE”. How could I make the vertical scrollbar scroll the canvas_v?

The MWE has been updated and the result is:

NEW MWE

from customtkinter import CTk, CTkFrame, CTkScrollbar
from tkinter import Canvas

def scroll_x(*args):
    """Scroll horizontally for scrollbar movements."""
    canvas_h.xview(*args)

def scroll_y(*args):
    """Scroll vertically for scrollbar movements."""
    canvas_v.yview(*args)
    
def handle_mousewheel(event):
    """Scroll vertically for mouse wheel."""
    canvas_v.yview_scroll(int(-1*(event/120)), "units")
    
def handle_mousewheel_shift(event):
    """Scroll horizontally for mouse wheel.."""
    canvas_h.xview_scroll(int(-1*(event/120)), "units")
    
root = CTk()

frame_h = CTkFrame(root, fg_color="blue")
frame_h.grid(column=0, row=0, sticky='nsew')

# Define horizontal scrollbar
hsb = CTkScrollbar(root, orientation='horizontal', command=scroll_x)
hsb.grid(column=0, row=1, sticky='ew')

# Make grid resizeable
root.grid_columnconfigure(0, weight=1)
root.grid_rowconfigure(0, weight=1)

# Canvas with internal frame for horizontal scrollable frame
canvas_h = Canvas(frame_h, width=200, height=300)
frame_canvas_h = CTkFrame(canvas_h, fg_color="cyan")
canvas_h.config(xscrollcommand=hsb.set, highlightthickness=0)
canvas_h.pack(fill='both', side='left', expand=True)
canvas_h.create_window(0, 0, window=frame_canvas_h, anchor='nw')

# Get the colorful frames
column_frames = []
column_frames.append(CTkFrame(frame_canvas_h, fg_color="teal"))
column_frames[0].grid(column=0, row=0)

##### Start working on vertical scrollable frame
frame_v = CTkFrame(frame_canvas_h, fg_color="red")
frame_v.grid(column=1, row=0, sticky="nswe")

# Define vertical scrollbar
vsb = CTkScrollbar(root, orientation='vertical', command=scroll_y)
vsb.grid(column=1, row=0, rowspan=2, sticky='ew')

# Make grid resizeable
frame_h.grid_columnconfigure(0, weight=1)
frame_h.grid_rowconfigure(0, weight=1)

# Canvas with internal frame for vertical scrollable frame
canvas_v = Canvas(frame_v, width=500, height=300)
frame_canvas_v = CTkFrame(canvas_v, fg_color="pink")
canvas_v.config(yscrollcommand=vsb.set, highlightthickness=0)
canvas_v.pack(fill='both', side='left', expand=True)
canvas_v.create_window(0, 0, window=frame_canvas_v, anchor='nw')

# Get the colorful frames
column_frames.append(CTkFrame(frame_canvas_v, fg_color="orange"))
column_frames.append(CTkFrame(frame_canvas_v, fg_color="yellow"))
column_frames[1].grid(column=0, row=0)
column_frames[2].grid(column=1, row=0)

# Size canvases to size of frame with widgets
canvas_h.update_idletasks()
canvas_v.update_idletasks()

canvas_h.config(scrollregion=frame_canvas_h.bbox("all"))
canvas_v.config(scrollregion=frame_canvas_v.bbox("all"))

root.mainloop()

OLD MWE

from customtkinter import CTkFrame, CTk, CTkScrollableFrame
from tkinter import LEFT

root = CTk()

# Create a horizontal scrollable frame
h_scroll_frame = CTkScrollableFrame(root, orientation="horizontal")
h_scroll_frame.pack(fill="both", expand=True)

# Create a vertical scrollable frame
v_scroll_frame = CTkScrollableFrame(h_scroll_frame, fg_color="red")

# Create the first of the column_frames, outside of vertical scrolling
column_frames = [CTkFrame(h_scroll_frame, fg_color="blue")]
column_frames[0].pack(side=LEFT, fill="both", expand=False)
v_scroll_frame.pack(side=LEFT, fill="both", expand=True)

# Add two more column_frames, inside of vertical scrolling
for column in range(1, 3):
    column_frames.append(CTkFrame(v_scroll_frame))
    column_frames[column].grid(column=column, row=0, sticky="NWE", padx=0, pady=0)

# Add a boxed frame inside each of the column_frames
colors = ["teal", "orange", "yellow"]
for index_column, column in enumerate(column_frames):
    frame = CTkFrame(column, fg_color=colors[index_column], border_color="black", border_width=3)
    frame.grid(column=0, row=0)

root.mainloop()

7

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật