Как создать полосу прокрутки для комбобокса ctkPython

Программы на Python
Anonymous
Как создать полосу прокрутки для комбобокса ctk

Сообщение Anonymous »

Код: Выделить всё

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.

Подробнее здесь: https://stackoverflow.com/questions/790 ... k-combobox

Вернуться в «Python»