CustomTkinter Documentation

repository·master·Indexed 12 days ago

https://github.com/tomschimansky/customtkinter

A Python UI library built on top of Tkinter providing modern, customizable widgets with HighDPI scaling and system appearance adaptation (light/dark mode) for Windows, macOS, and Linux.

Tokens
699
Snippets
4
Records
6
Agent score
46%

What's inside CustomTkinter

  1. Install CustomTkinter via pip

    master

    Install the customtkinter module using pip. It is recommended to update frequently as the library is under active development.

    To install:

    pip3 install customtkinter

    To update an existing installation:

    pip3 install customtkinter --upgrade
    pip3 install customtkinter
  2. Create a basic CustomTkinter application

    master

    To create a window, use customtkinter.CTk(). This is the CustomTkinter equivalent of the standard Tkinter Tk window. Widgets like CTkButton are used instead of standard tkinter widgets to ensure modern styling and HighDPI scaling support.

    import customtkinter
    
    customtkinter.set_appearance_mode("System")
    customtkinter.set_default_color_theme("blue")
    
    app = customtkinter.CTk()  # create CTk window
    app.geometry("400x240")
    
    def button_function():
        print("button pressed")
    
    # Use CTkButton instead of tkinter Button
    button = customtkinter.CTkButton(master=app, text="CTkButton", command=button_function)
    button.place(relx=0.5, rely=0.5, anchor=customtkinter.CENTER)
    
    app.mainloop()
  3. Configure appearance mode and color themes

    master

    CustomTkinter allows you to set the global appearance mode and the default color theme for all widgets.

    Appearance Modes:

    • "System" (default): Adapts to the operating system's light/dark mode.
    • "light": Forces light mode.
    • "dark": Forces dark mode.

    Color Themes:

    • "blue" (default)
    • "dark-blue"
    • "green"
    import customtkinter
    
    customtkinter.set_appearance_mode("System")  # Modes: system, light, dark
    customtkinter.set_default_color_theme("blue")  # Themes: blue, dark-blue, green