有没有办法改变 tkcalendar 的颜色? [英] Is there a way to change tkcalendar's color?

查看:21
本文介绍了有没有办法改变 tkcalendar 的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让 tkcalendar 与我的窗口融为一体.

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()

我已经通读了 tkcalendar 文档并尝试通过调用小部件类的配置方法来更改所有样式元素:

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?

推荐答案

你做对了,只是 OSX 默认主题不支持改变背景颜色(我认为它是基于图片的,所以你只能改变文字颜色).解决方案是使用不同的 ttk 主题(例如 clam 或 alt):

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()

顺便说一下,选项'borderbackground'不存在,正确的名称是'bordercolor'.

By the way, the option 'borderbackground' does not exists, the correct name is 'bordercolor'.

这篇关于有没有办法改变 tkcalendar 的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆