Skip to content

CTk (tkinter.Tk)

Tom Schimansky edited this page Dec 2, 2022 · 18 revisions

Theoretically you could also use the normal tkinter.Tk class to create a window and place CTK widgets on it, but it is highly recommended to use the customtkinter.CTk to create the window if you use CustomTkinter. Because only with the CTk window you get a dark window background and header which adapts to the dark/light mode set by customtkinter.set_appearance_mode(...).

Apart from the changing background and header color, the CTk class behaves exactly like the tkinter.Tk class.

Example Code:

app = customtkinter.CTk()
app.geometry(f"{600}x{500}")
app.title("CTk example")

... program ...

app.mainloop()
class App(customtkinter.CTk):
    def __init__(self):
        super().__init__()

        self.geometry(f"{600}x{500}")
        self.title("CTk example")

        ... create widgets ...

    ... program methods ...

app = App()
app.mainloop()

Arguments:

argument value
fg_color window background color, tuple: (light_color, dark_color) or single color

Methods:

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

    All attributes can be configured and updated.

    app.configure(fg_color=new_fg_color)
  • .cget(attribute_name)

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

    fg_color = app.cget("fg_color")
    ...
  • .title(string)

    Set title of window.

  • .geomtry(geometry_string)

    Set geometry and positions of the window like this: "<width>x<height>" or "<width>x<height>+<x_pos>+<y_pos>"

  • .minsize(width, height)

    Set minimal window size.

  • .maxsize(width, height)

    Set max window size.

  • .resizable(width, height)

    Define, if width and/or height should be resizablee with bool values.

  • .after(milliseconds, command)

    Execute command after milliseconds without blocking the main loop.

  • .withdraw()

    Hide window and icon. Restore it with .deiconify().

  • .iconify()

    Iconifies the window. Restore it with .deiconify().

  • .deiconify()

    Deiconify the window.

  • .state()

    Returns the window state: 'normal', 'iconic' or 'withdrawn'

⚠️ Attention ⚠️

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

https://customtkinter.tomschimansky.com

Clone this wiki locally