1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] How to create a scrollbar for ctk combobox

Discussão em 'Python' iniciado por Stack, Outubro 1, 2024 às 10:43.

  1. Stack

    Stack Membro Participativo

    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 ()

    I have the above code help me out.

    I am expecting a scrollbar for my ctk combobox widget.

    Continue reading...

Compartilhe esta Página