Skip to content

CTkOptionMenu

Tom Schimansky edited this page Sep 15, 2022 · 17 revisions
Bildschirmfoto 2022-08-15 um 18 55 27

Example Code:

Without variable:

def optionmenu_callback(choice):
    print("optionmenu dropdown clicked:", choice)

combobox = customtkinter.CTkOptionMenu(master=app,
                                       values=["option 1", "option 2"],
                                       command=optionmenu_callback)
combobox.pack(padx=20, pady=10)
combobox.set("option 2")  # set initial value

With variable:

optionmenu_var = customtkinter.StringVar(value="option 2")  # set initial value

def optionmenu_callback(choice):
    print("optionmenu dropdown clicked:", choice)

combobox = customtkinter.CTkComboBox(master=app,
                                     values=["option 1", "option 2"],
                                     command=optionmenu_callback,
                                     variable=optionmenu_var)
combobox.pack(padx=20, pady=10)

Arguments:

argument value
master root, frame, top-level
width box width in px
height box height in px
corner_radius corner radius in px
border_width border width in px
fg_color foreground (inside) color, tuple: (light_color, dark_color) or single color
bg_color background color, tuple: (light_color, dark_color) or single color, default is None
button_color right button color, tuple: (light_color, dark_color) or single color
button_hover_color hover color, tuple: (light_color, dark_color) or single color
dropdown_color dropdown fg color, tuple: (light_color, dark_color) or single color
dropdown_hover_color dropdown button hover color, tuple: (light_color, dark_color) or single color
dropdown_text_color dropdown text color, tuple: (light_color, dark_color) or single color
text_color text color, tuple: (light_color, dark_color) or single color
text_color_disabled text color when disabled, tuple: (light_color, dark_color) or single color
text_font button text font, tuple: (font_name, size)
dropdown_text_font button text font, tuple: (font_name, size)
hover enable/disable hover effect: True, False
state "normal" (standard) or "disabled" (not clickable, darker color)
command function will be called when the dropdown is clicked manually
variable StringVar to control or get the current text
values list of strings with values that appear in the option menu dropdown
dynamic_resizing enable/disable automatic resizing of optiomenu when text is too big to fit: True (standard), False

Methods:

current_value = optionmenu.get()
optionmenu.set(new_value)
optionmenu.configure(values=["new value 1", "new value 2"])
optionmanu.configure(...)

⚠️ Attention ⚠️

The Github Wiki is outdated, the new documentation can be found at:

https://customtkinter.tomschimansky.com

Clone this wiki locally