有没有办法改变 tkcalendar 的颜色?
Is there a way to change tkcalendar's color?
我正在尝试让 tkcalendar 融入我的 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()
我通读了 tkcalendar 文档并尝试通过调用小部件的配置方法来更改所有样式元素 class :
cal.configure(background = "black")
;然而,我的日历仍然是灰色的,而不是融入黑色 window 背景。是否可以更改日历的实际背景颜色?
tkcalendar
模块中的 Calendar
class 是 subclass of ttk.Frame
.
class Calendar(ttk.Frame):
您必须使用使用主题更改其属性的 styling specific to ttk。
你做的是对的,除了OSX默认主题不支持改变背景颜色(我认为它是基于图片所以你只能改变文本颜色)。
解决方案是使用不同的 ttk 主题(例如 clam 或 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()
顺便说一下,选项'borderbackground'不存在,正确的名字是'bordercolor'。
我正在尝试让 tkcalendar 融入我的 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()
我通读了 tkcalendar 文档并尝试通过调用小部件的配置方法来更改所有样式元素 class :
cal.configure(background = "black")
;然而,我的日历仍然是灰色的,而不是融入黑色 window 背景。是否可以更改日历的实际背景颜色?
tkcalendar
模块中的 Calendar
class 是 subclass of ttk.Frame
.
class Calendar(ttk.Frame):
您必须使用使用主题更改其属性的 styling specific to ttk。
你做的是对的,除了OSX默认主题不支持改变背景颜色(我认为它是基于图片所以你只能改变文本颜色)。 解决方案是使用不同的 ttk 主题(例如 clam 或 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()
顺便说一下,选项'borderbackground'不存在,正确的名字是'bordercolor'。