Python CustomTkinterでのボタンカスタマイズ方法

まくまく
まくまく
CustomTkinter で作成したボタンのカスタマイズをしてみようと思います!!



サンプルプログラム

import customtkinter

class App(customtkinter.CTk):
    def __init__(self):
        super().__init__()

        self.title("minimal example app")
        self.minsize(400, 300)

        self.button1 = customtkinter.CTkButton(master=self, text="Button1", command=self.button_callback)
        self.button1.pack(pady=10)

        self.button2 = customtkinter.CTkButton(master=self,
                                 width=300,
                                 height=50,
                                 border_width=0,
                                 corner_radius=10,
                                 text="Button2",
                                 text_color = "black",
                                 fg_color="red",
                                 command=self.button_callback)
        self.button2.pack(pady=10)

        self.button3 = customtkinter.CTkButton(master=self,
                                 width=100,
                                 height=50,
                                 border_width=0,
                                 corner_radius=25,
                                 text="Button3",
                                 text_color = "white",
                                 fg_color="#6633cc",
                                 command=self.button_callback)
        self.button3.pack(pady=10)
        
    def button_callback(self):
        print("button pressed")

if __name__ == "__main__":
    app = App()
    app.mainloop()

角丸具合が調整できるのが良いですね。あとデフォルトのテキスト文字色は白じゃないっぽいので、くっきりさせたい場合は指定した方がよいかもです。その他設定できる項目はこちらから参照ください。

タイトルとURLをコピーしました