问题
I'm trying to make tkcalendar blend in with my window.
import tkinter
from tkcalendar import Calendar
window = tkinter.Tk()
window.configure(background = "black")
cal = Calendar(window, background = "black" , disabledbackground = "black" , borderbackground = "black" , headersbackground = "black" , normalbackground = "black" )
cal.config(background = "black")
cal.pack()
window.mainloop()
I've read through the tkcalendar documentation and tried changing all the style elements by calling the configure method of widget class :
cal.configure(background = "black")
; however, my calendar still remains gray instead of blending into the black window background. Is it possible to change the actual background color of the calendar?
回答1:
You are doing it the right way, except that OSX default theme does not support changing background colors (it is based on pictures I think so you can only change the text color). The solution is to use a different ttk theme (e.g. clam or alt):
import tkinter
from tkinter import ttk
from tkcalendar import Calendar
window = tkinter.Tk()
window.configure(background = "black")
style = ttk.Style(window)
style.theme_use('clam') # change theme, you can use style.theme_names() to list themes
cal = Calendar(window, background="black", disabledbackground="black", bordercolor="black",
headersbackground="black", normalbackground="black", foreground='white',
normalforeground='white', headersforeground='white')
cal.config(background = "black")
cal.pack()
By the way, the option 'borderbackground' does not exists, the correct name is 'bordercolor'.
回答2:
The Calendar
class in tkcalendar
module is a subclass of ttk.Frame.
class Calendar(ttk.Frame):
You must use the styling specific to ttk that uses themes to alter its attributes.
来源:https://stackoverflow.com/questions/61493630/is-there-a-way-to-change-tkcalendars-color