-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Description
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
- Create a
CTkButton
instance with an image. - Set
width
andheight
to the same value (e.g.,width=35
,height=35
). - Set
corner_radius
to a non-zero value (e.g.,corner_radius=15
). - Add a square image (e.g., 20x20 pixels) to the button.
- 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

Metadata
Metadata
Assignees
Labels
No labels