[Python] CustomTkinter: Background of button with rounded corner still got edges

Discussão em 'Python' iniciado por Stack, Julho 8, 2025.

  1. Stack

    Stack Membro Participativo

    I used CTK to round the corners of my buttons, it did work, but not as expected. In the background of the button, there is still something that doesn't get the round corners Image to it I don't see what causes it though, maybe because the button is in a grid?

    import customtkinter as ctk
    import webbrowser
    from PIL import Image

    def on_press(event, button, ID):
    button.configure(bg_color="#009A5F") # Darker shade of #00B06F
    open_place(ID) # Open the place when button is pressed
    return "break" # Prevent the default button behavior and animation

    def on_release(event, button):
    button.configure(bg_color="#00B06F") # Original color

    # Create a frame for each entry in the data and arrange in a grid
    row, column = 0, 0
    for name, info in Data.items():
    frame = ctk.CTkFrame(root, width=CWidth, height=CHeight, corner_radius=20) # Added corner_radius
    frame.grid_propagate(False) # Prevent the frame from resizing to the content

    # Game name label at the top with updated styling
    game_name_label = ctk.CTkLabel(frame, text=name, font=("Arial", 12, "bold"), anchor="center", text_color="white", bg_color="#111216", corner_radius=10)
    game_name_label.grid(row=1, column=0, sticky="ew", padx=5, pady=5)

    # Play button at the bottom, 100% width with custom button color and rounded corners
    button = ctk.CTkButton(frame, text="Play", fg_color="#00B06F", hover_color="#009A5F", height=40, corner_radius=15)
    button.grid(row=2, column=0, sticky="ew", padx=5, pady=(3, 5)) # Use sticky='ew' to stretch it horizontally

    # Bind the button press and release events
    button.bind("<ButtonPress-1>", lambda event, btn=button, ID=info["ID"]: on_press(event, btn, ID))
    button.bind("<ButtonRelease-1>", lambda event, btn=button: on_release(event, btn))

    # Add the frame to the root window in a grid, with 5px padding between frames
    frame.grid(row=row, column=column, padx=5, pady=5)

    # Configure the grid of the frame to have 3 rows and 1 column, and stretch elements
    frame.grid_rowconfigure(0, weight=1) # Label row stays at the top without stretching
    frame.grid_rowconfigure(1, weight=0) # Empty row to make sure there's space for the label and button
    frame.grid_rowconfigure(2, weight=0) # Button row stays at the bottom without stretching

    # Configure the column of the frame
    frame.grid_columnconfigure(0, weight=1) # The single column will expand horizontally

    Continue reading...

Compartilhe esta Página