Skip to content

Square buttons with rounded corners become distorted when adding an image #2758

@guguss-31

Description

@guguss-31

Description

Context:
I'm using the customtkinter library to create a GUI with square buttons that have rounded corners. However, when I add an image to these buttons, their shape becomes rectangular (width appears larger than height) instead of staying square.

Expected Behavior:
Buttons should maintain a square shape (width = height) with rounded corners, even when an image is inserted.

Current Behavior:
Buttons lose their square shape and become rectangular (width exceeds height) as soon as an image is added.


Steps to Reproduce

  1. Create a CTkButton instance with an image.
  2. Set width and height to the same value (e.g., width=35, height=35).
  3. Set corner_radius to a non-zero value (e.g., corner_radius=15).
  4. Add a square image (e.g., 20x20 pixels) to the button.
  5. Observe that the button is no longer square.

Minimal Code Example

Here’s a code snippet that reproduces the issue:

import customtkinter
from PIL import Image

customtkinter.set_appearance_mode("dark")

# Example of a button with an image
def create_button_with_image(master, image_path):
    image = customtkinter.CTkImage(light_image=Image.open(image_path), dark_image=Image.open(image_path), size=(20, 20))
    return customtkinter.CTkButton(
        master,
        text="",
        image=image,
        fg_color="#6BCF7F",
        hover_color="#2E8B57",
        corner_radius=15,  # Rounded corners
        width=35,           # Width
        height=35,          # Height
    )

# Create the window
app = customtkinter.CTk()
app.geometry("200x200")

# Add a button with an image
button = create_button_with_image(app, "datas/img/undo.png")
button.pack(pady=20)

app.mainloop()

Additional Information

  • customtkinter version: [5.2.2]
  • Operating System: [Windows 11]
  • Python version: [Python 3.13.7]

Screenshot

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions