import customtkinter as ctk
from tkinter import StringVar
def show_options():
global option_frame
# If the frame is already open, close it
if option_frame is not None:
option_frame.destroy()
# Create a new scrollable frame
option_frame = ctk.CTkScrollableFrame(root, width=200, height=150)
option_frame.place(x=dropdown_button.winfo_x(), y=dropdown_button.winfo_height() + 10)
# Add buttons for each option
for option in options:
option_button = ctk.CTkButton(option_frame, text=option, command=lambda opt=option: select_option(opt))
option_button.pack(fill="x")
def select_option(option):
selected_value.set(option)
if option_frame is not None:
option_frame.destroy() # Close dropdown after selecting the option
# Main application setup
root = ctk.CTk()
root.geometry("400x400")
# List of options
options = [f"Option {i}" for i in range(1, 21)]
selected_value = StringVar(value=options[0])
option_frame = None
# Create the dropdown button
dropdown_button = ctk.CTkButton(root, textvariable=selected_value, command=show_options)
dropdown_button.pack(padx=20, pady=20, fill="x")
# Start the main loop
root.mainloop
()
Мне поможет приведенный выше код.
Я ожидаю полосу прокрутки для своего виджета со списком ctk.
Я пытаюсь сделать то же самое, что и в этом посте, но с реализацией в контейнере/элементе MUI Grid. Однако в результате у меня нет полосы прокрутки, и я не могу прокручивать. Что-то не так с моей реализацией?