Я использовал CTK, чтобы скруглить углы кнопок, это сработало, но не так, как ожидалось.
На фоне кнопки все еще есть что-то, у чего углы не закруглены
Изображение к нему
Я не понимаю, что является причиной этого, может быть, потому, что кнопка находится в сетке?
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("", lambda event, btn=button, ID=info["ID"]: on_press(event, btn, ID))
button.bind("", 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
Подробнее здесь: https://stackoverflow.com/questions/793 ... -got-edges
CustomTkinter: фон кнопки с закругленным углом все еще имеет края ⇐ Python
Программы на Python
-
Anonymous
1735305723
Anonymous
Я использовал CTK, чтобы скруглить углы кнопок, это сработало, но не так, как ожидалось.
На фоне кнопки все еще есть что-то, у чего углы не закруглены
Изображение к нему
Я не понимаю, что является причиной этого, может быть, потому, что кнопка находится в сетке?
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("", lambda event, btn=button, ID=info["ID"]: on_press(event, btn, ID))
button.bind("", 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
Подробнее здесь: [url]https://stackoverflow.com/questions/79311910/customtkinter-background-of-button-with-rounded-corner-still-got-edges[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия