Skip to content

CTkButton

Tom Schimansky edited this page Feb 5, 2023 · 15 revisions

Example Code:

Default theme:

def button_event():
    print("button pressed")

button = customtkinter.CTkButton(master=root_tk, text="CTkButton", command=button_event)
button.pack(padx=20, pady=10)

Customized:

button = customtkinter.CTkButton(master=root_tk,
                                 width=120,
                                 height=32,
                                 border_width=0,
                                 corner_radius=8,
                                 text="CTkButton",
                                 command=button_event)
button.place(relx=0.5, rely=0.5, anchor=tkinter.CENTER)

Arguments:

argument value
master root, tkinter.Frame or CTkFrame
width button width in px
height button height in px
corner_radius corner radius in px
border_width button border width in px
border_spacing spacing between text and image and button border in px, default is 2
fg_color forground color, tuple: (light_color, dark_color) or single color or "transparent"
hover_color hover color, tuple: (light_color, dark_color) or single color
border_color border 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 string
font button text font, tuple: (font_name, size), (set negative size value for size in pixels)
textvariable tkinter.StringVar object to change text of button
image put an image on the button, removes the text, must be class PhotoImage
state "normal" (standard) or "disabled" (not clickable, darker color)
hover enable/disable hover effect: True, False
command callback function
compound set image orientation if image and text are given ("top", "left", "bottom", "right")
anchor alignment of text an image in button ("n", "ne", "e", "se", "s", "sw", "w", "nw", "center")

Methods:

  • .configure(attribute=value, ...)

    All attributes can be configured and updated.

    ctk_button.configure(border_width=new_borderwidth)
    ctk_button.configure(image=new_image)
    ctk_button.configure(text=new_text)
    ctk_button.configure(command=callback_function)
    ...
  • .cget(attribute_name)

    Pass attribute name as string and get current value of attribute.

    state = ctk_button.cget("state")
    text = ctk_button.cget("text")
    ...
  • .invoke()

    Calls command if button state is 'disabled'.

⚠️ Attention ⚠️

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

https://customtkinter.tomschimansky.com

Clone this wiki locally