Skip to main content

CTkButton

Available since version 0.3.0.

Example Code​

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

button = customtkinter.CTkButton(app, text="CTkButton", command=button_event)
CTkButton example on macOS in dark mode
Changed in 6.0

The command is now called when the mouse button is released over the button, not when it is pressed. Moving the mouse away before releasing cancels the click, like with native buttons.

Arguments​

argumentvalue
masterroot, tkinter.Frame or CTkFrame
widthbutton width in px
heightbutton height in px
corner_radiuscorner radius in px
border_widthbutton border width in px
border_spacingspacing between text and image and button border in px, default is 2
bg_colorcolor behind the widget, only visible at the rounded corners, "transparent" (default) takes the color of the parent widget, tuple: (light_color, dark_color) or single color
fg_colorforground color, tuple: (light_color, dark_color) or single color or "transparent"
hover_colorhover color, tuple: (light_color, dark_color) or single color
border_colorborder color, tuple: (light_color, dark_color) or single color
text_colortext color, tuple: (light_color, dark_color) or single color
text_color_disabledtext color when disabled, tuple: (light_color, dark_color) or single color
background_corner_colorstuple of four colors for the background behind the corners (top left, top right, bottom right, bottom left), useful if the button sits between differently colored areas, default is None
round_width_to_even_numbersround the drawn width to even numbers for crisper shapes, default is True
round_height_to_even_numbersround the drawn height to even numbers for crisper shapes, default is True
textstring
fontbutton text font, tuple: (font_name, size), (set negative size value for size in pixels)
textvariabletkinter.StringVar object to change text of button
imageput an image on the button, removes the text, must be class PhotoImage
state"normal" (standard) or "disabled" (not clickable, darker color)
hoverenable/disable hover effect: True, False
commandfunction will be called when the button is clicked; since 6.0 the command is called when the mouse button is released over the button
compoundset image orientation if image and text are given ("top", "left", "bottom", "right")
anchoralignment of text an image in button ("n", "ne", "e", "se", "s", "sw", "w", "nw", "center")

Arguments and methods that all widgets share, like bg_color, .bind(), .focus() or .destroy(), are described on Common arguments and methods.

Methods​

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

    All attributes can be configured, for example:

    button.configure(text="new text")
  • .cget(attribute_name)​

    Pass attribute name as string and get current value of attribute, for example.

    text = button.cget("text")
  • .invoke()​

    Calls command if button state is 'disabled'.