CTkMessagebox Documentation

repository·main·Indexed 18 days ago

https://github.com/akascape/ctkmessagebox

A customizable messagebox extension for CustomTkinter that provides modern, styled alerts with built-in icons and animation effects. It supports various alert types (Info, Success, Error, Warning, Question), custom icons via file paths, and extensive styling options for buttons, colors, and window layout. User responses can be captured using the .get() method.

Tokens
1K
Snippets
4
Records
5
Agent score
14%

What's inside CTkMessagebox

  1. Use custom icons in CTkMessagebox

    main

    While the library provides 5 default icons (check, cancel, warning, question, info), you can use your own images by passing the file path to the icon parameter.

    CTkMessagebox(message="Custom Icon Example", icon="path/to/your/image.png")
  2. Use CTkMessagebox for information and alerts

    main

    You can instantiate CTkMessagebox to show different types of alerts by specifying the icon parameter.

    Common patterns include:

    • Info: Default behavior.
    • Success: Use icon="check".
    • Error: Use icon="cancel".
    • Warning: Use icon="warning".
    • Question: Use icon="question".

    To show a simple information box:

    from CTkMessagebox import CTkMessagebox
    CTkMessagebox(title="Info", message="This is a CTkMessagebox!")
    from CTkMessagebox import CTkMessagebox
    import customtkinter
    
    def show_info():
        # Default messagebox for showing some information
        CTkMessagebox(title="Info", message="This is a CTkMessagebox!")
  3. Get user responses from CTkMessagebox

    main

    To capture user input from buttons (like Yes/No or Retry/Cancel), store the CTkMessagebox instance in a variable and call its .get() method. The method returns the text of the button that was clicked.

    msg = CTkMessagebox(title="Exit?", message="Do you want to close?",
                        icon="question", option_1="Cancel", option_2="No", option_3="Yes")
    response = msg.get()
    
    if response == "Yes":
        # Perform action
        pass
  4. Configure CTkMessagebox options and appearance

    main

    The CTkMessagebox constructor accepts a wide range of parameters to customize its appearance and behavior.

    Core Content

    • title: The title of the messagebox.
    • message: The main text displayed in the center.
    • icon: The icon to display (e.g., "check", "cancel", "warning", "question", or a path to a custom image).

    Button Customization

    • option_1, option_2, option_3: Text for the first, second, and third buttons. (Default for option_1 is 'OK').
    • options: A list containing the button texts in order.
    • button_color: Color of the buttons.
    • button_text_color: Color of the text inside the buttons.
    • button_hover_color: Color of the buttons when hovered.
    • button_width / button_height: Dimensions of the buttons in px.
    • justify: Position the buttons ("center", "right", or "left").

    Window & Layout

    • master: The parent window (the box will spawn at the center of this window).
    • width / height: Dimensions of the messagebox window in px.
    • fg_color: Foreground color of the middle portion.
    • bg_color: Background color of the messagebox.
    • corner_radius: Corner roundness (Note: not applicable on Linux).
    • fade_in_duration: Duration for fade-in/out animation (integer, default is 0).
    • topmost: Whether to disable the topmost window outside the app (bool).

    Styling & Text

    • text_color: Color of the message text.
    • title_color: Color of the title text.
    • font: Font of the messagebox text (tuple).
    • wraplength: Text wrapping length.

    Icon & Border

    • icon_size: Size of the icon image (tuple).
    • border_width: Width of the border around the main frame (default is 1).
    • border_color: Color of the frame border.
    • cancel_button: Define the close button type ("circle", "cross", or None).
    • cancel_button_color: Color of the close button (set to 'transparent' to hide it).