Colors
gcsa allows you to retrieve a list of available calendar and event colors with their ids.
To do so, create a GoogleCalendar
instance (see Getting started to get your
credentials):
from gcsa.google_calendar import GoogleCalendar
gc = GoogleCalendar()
Note
Event colors
List event colors
for color_id, color in gc.list_event_colors().items():
bg = color['background']
fg = color['foreground']
print(color_id, f'{bg=}, {fg=}')
Color ID |
Name |
Classic |
Modern |
---|---|---|---|
‘1’ |
Lavender |
#A4BDFC |
#7986CB |
‘2’ |
Sage |
#7AE7BF |
#33B679 |
‘3’ |
Grape |
#DBADFF |
#8E24AA |
‘4’ |
Flamingo |
#FF887C |
#E67C73 |
‘5’ |
Banana |
#FBD75B |
#F6BF26 |
‘6’ |
Tangerine |
#FFB878 |
#F4511E |
‘7’ |
Peacock |
#46D6DB |
#039BE5 |
‘8’ |
Graphite |
#E1E1E1 |
#616161 |
‘9’ |
Blueberry |
#5484ED |
#3F51B5 |
‘10’ |
Basil |
#51B749 |
#0B8043 |
‘11’ |
Tomato |
#DC2127 |
#D50000 |
None |
Color of the calendar |
Set event color
Use color ID in Event
’s color_id field:
from gcsa.event import Event
FLAMINGO_COLOR_ID = '4'
event = Event('Important!',
start=start,
color_id=FLAMINGO_COLOR_ID)
event = gc.add_event(event)
Update event color
FLAMINGO_COLOR_ID = '4'
event.color_id = FLAMINGO_COLOR_ID
gc.update_event(event)
Calendar colors
Note
Color is a property of a calendar list entry, not a calendar itself (see the difference in Calendars and Calendar list). Unlike events’ colors, you can use either the color ID or hex values to set a color for a calendar list entry. If you use hex values (they are not limited to values from the table bellow), value of the color ID will be set automatically to the best matching option.
List calendar colors
for color_id, color in gc.list_calendar_colors().items():
bg = color['background']
fg = color['foreground']
print(color_id, f'{bg=}, {fg=}')
Color ID |
Name |
Classic |
Modern |
---|---|---|---|
‘1’ |
Cocoa |
#AC725E |
#795548 |
‘2’ |
Flamingo |
#D06B64 |
#E67C73 |
‘3’ |
Tomato |
#F83A22 |
#D50000 |
‘4’ |
Tangerine |
#FA573C |
#F4511E |
‘5’ |
Pumpkin |
#FF7537 |
#EF6C00 |
‘6’ |
Mango |
#FFAD46 |
#F09300 |
‘7’ |
Eucalyptus |
#42D692 |
#009688 |
‘8’ |
Basil |
#16A765 |
#0B8043 |
‘9’ |
Pistachio |
#7BD148 |
#7CB342 |
‘10’ |
Avocado |
#B3DC6C |
#C0CA33 |
‘11’ |
Citron |
#FBE983 |
#E4C441 |
‘12’ |
Banana |
#FAD165 |
#F6BF26 |
‘13’ |
Sage |
#92E1C0 |
#33B679 |
‘14’ |
Peacock |
#9FE1E7 |
#039BE5 |
‘15’ |
Cobalt |
#9FC6E7 |
#4285F4 |
‘16’ |
Blueberry |
#4986E7 |
#3F51B5 |
‘17’ |
Lavender |
#9A9CFF |
#7986CB |
‘18’ |
Wisteria |
#B99AFF |
#B39DDB |
‘19’ |
Graphite |
#C2C2C2 |
#616161 |
‘20’ |
Birch |
#CABDBF |
#A79B8E |
‘21’ |
Radicchio |
#CCA6AC |
#AD1457 |
‘22’ |
Cherry Blossom |
#F691B2 |
#D81B60 |
‘23’ |
Grape |
#CD74E6 |
#8E24AA |
‘24’ |
Amethyst |
#A47AE2 |
#9E69AF |
Set calendar list entry color
Use color ID in CalendarListEntry
’s color_id field or hex values in background_color and
foreground_color:
Get a calendar list entry
calendar_list_entry = gc.get_calendar_list_entry('<calendar_id>')
Set a new color ID
GRAPHITE_COLOR_ID = '19'
calendar_list_entry.color_id = GRAPHITE_COLOR_ID
or set hex values of background_color and foreground_color:
calendar_list_entry.background_color = "#626364"
calendar_list_entry.foreground_color = "#FFFFFF"
Update calendar list entry:
calendar_list_entry = gc.update_calendar_list_entry(calendar_list_entry)