ボタン

CustomTkinter

背景色の変更

btn = ct.CTkButton(fg_color="#f44336")

ボタン内に画像とテキストを配置

# 前提
・透過PNG画像をctk.pyと同階層に入れておく
・PILのインストール

from PIL import Image

trashbox_img = ct.CTkImage(
  light_image=Image.open("icon-trashbox.png"),
  dark_image=Image.open("icon-trashbox.png"),
  size=(14, 14)   # テキストが14pxなので合わせる
)


delete_btn = ct.CTkButton(
  tab_top_frame,
  text="削除",
  image=trashbox_img,
  compound="left",  # 画像がテキストの左側にくる
  width=100,
  height=35,
  command=delete_tab_local
)
delete_btn.pack(side="left", padx=5)

# テキストと画像を並べるとテキストが少し浮くので、テキストを少し下に下げる
delete_btn._text_label.configure(pady=8)

BACK