Skip to main content

Common arguments and methods

All CustomTkinter widgets are built on the same base class, so some arguments and methods work the same way on every widget. The pages of the individual widgets only list what is specific to them.

Common arguments​

argumentvalue
masterparent of the widget: the main window (CTk), a CTkToplevel, a CTkFrame or a tab of a CTkTabview
widthwidth in px, must be passed when the widget is created, not to .place()
heightheight in px, must be passed when the widget is created, not to .place()
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_colormain color of the widget, tuple: (light_color, dark_color) or single color, some widgets also accept "transparent"

All sizes and paddings are given in px at 100% scaling. CustomTkinter multiplies them with the widget scaling factor, see Scaling. How colors can be set is explained on Color and Themes.

Common methods​

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

    Change one or more attributes after the widget was created. An attribute that the widget does not support raises a ValueError. The tkinter method .config() is not available, use .configure() instead.

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

    Returns the current value of an attribute, pass the name as a string.

    text = button.cget("text")
  • .bind(sequence=None, command=None, add=True)​

    Bind a function to an event, like in tkinter. The add argument can only be "+" or True, so the internal callbacks of the widget are kept.

    def on_enter(event):
    print("mouse entered the button")

    button.bind("<Enter>", on_enter)
  • .unbind(sequence=None, funcid=None)​

    Remove all functions you bound to the event sequence. funcid must be None, the internal callbacks of the widget are restored automatically. .bind_all() and .unbind_all() are not allowed on CustomTkinter widgets.

  • .focus(), .focus_set(), .focus_force()​

    Give the keyboard focus to the widget.

  • .destroy()​

    Remove the widget and all its child widgets.

  • .pack(...), .grid(...), .place(...)​

    Place the widget in its parent with one of the tkinter layout managers, the arguments are the same as in tkinter. Padding values like padx and pady are scaled together with the widget. See the grid tutorial for an introduction.

  • .pack_forget(), .grid_forget(), .place_forget()​

    Hide the widget again without destroying it.