3

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?

enter image description here

jossefaz
  • 3,312
  • 4
  • 17
  • 40
blueblast
  • 87
  • 2
  • 10
  • 1
    As far as i know : tkcalendar is a widget. And in the documentation it says that it inherits from all the widgets methods of tkinter. So change cal.config to cal.configure and it should do the trick – jossefaz Apr 29 '20 at 03:29
  • @yAzou I tried that and no luck there. It only changes the little arrow colors – blueblast Apr 29 '20 at 03:34
  • 1
    okay, i edit your post to add that you also tired to call the inherited method `configure` of widget...it should be useful for who will read your post – jossefaz Apr 29 '20 at 03:44

2 Answers2

4

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'.

screenshot

j_4321
  • 15,431
  • 3
  • 34
  • 61
  • Any option to change the font color? – Delrius Euphoria Dec 20 '20 at 22:49
  • @CoolCloud The font of which part? Because you can change separately the font color of the month and year, of the header, of normal days, of week-end days, .... It's all written in the [documentation](https://tkcalendar.readthedocs.io/en/stable/Calendar.html#class) – j_4321 Dec 20 '20 at 23:04
1

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.

Reblochon Masque
  • 35,405
  • 10
  • 55
  • 80