pythonuser-interfacetkintercustomtkinter

Can't change the background color of window in `customtkinter`


I am trying to change the background color of a CTk window using customtkinter, but nothing seems to work. Regardless of what color I try to set, the window always shows the system default dark background color. Here’s what I have tried so far:

import customtkinter as ctk

# Attempt to set background color directly in constructor
window = ctk.CTk(bg_color='red')

window.mainloop()

I also tried using the configure method:

import customtkinter as ctk

window = ctk.CTk()

# Attempt to configure background color after initialization
window.configure(bg_color='red')

window.mainloop()

But neither of these methods change the background color of the window. It remains the default dark color provided by customtkinter.


Solution

  • customtkinter use fg_color to set the background color:

    window.configure(fg_color='red')
    

    See official document.