Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ Widget keyword options

showweeknumbers : bool (default is True)
whether to display week numbers.


weeknumberoffset : int (default is 0)
to adjust the week numbers

showothermonthdays : bool (default is True)
whether to display the last days of the previous month and the first of the next month.

Expand Down Expand Up @@ -218,6 +221,9 @@ Widget keyword options
tooltipdelay : int
delay in ms before displaying the tooltip

day_names : 'wide' or 'short' or 'abbreviated'or 'narrow' (default = 'abbreviated')
contorl the fromat of the day name. Ex: 'Tuesday', 'Tu', 'Tue', 'T'

Virtual Events
~~~~~~~~~~~~~~

Expand Down
4 changes: 3 additions & 1 deletion tests/test_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def test_calendar_textvariable(self):
widget.pack()
self.window.update()
self.assertEqual('', var.get())
self.assertEqual('', widget.get_date())
self.assertEqual('1/3/15', widget.get_date()) # if textvariable == '' then year/month/day should still be horner
self.assertEqual(date(2015, 1, 1), widget._date)
widget.selection_set(date(2018, 11, 21))
self.window.update()
Expand Down Expand Up @@ -294,6 +294,7 @@ def test_calendar_get_set(self):
'firstweekday',
'weekenddays',
'showweeknumbers',
'weeknumberoffset',
'showothermonthdays',
'selectbackground',
'selectforeground',
Expand All @@ -316,6 +317,7 @@ def test_calendar_get_set(self):
'headersforeground',
'disableddaybackground',
'disableddayforeground',
'day_names',
'tooltipbackground',
'tooltipforeground',
'tooltipalpha',
Expand Down
17 changes: 15 additions & 2 deletions tkcalendar/calendar_.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ def __init__(self, master=None, **kw):
showweeknumbers : bool (default is True)
whether to display week numbers.

weeknumberoffset : int (default is 0)
to adjust the week numbers

showothermonthdays : bool (default is True)
whether to display the last days of the previous month and the first of the next month.

Expand Down Expand Up @@ -182,6 +185,9 @@ def __init__(self, master=None, **kw):
disableddayforeground : str
foreground color of days in disabled state

day_names : 'wide' or 'short' or 'abbreviated'or 'narrow' (default = 'abbreviated')
contorl the fromat of the day name. Ex: 'Tuesday', 'Tu', 'Tue', 'T'

Tooltip Options (for calevents)
-------------------------------

Expand Down Expand Up @@ -255,14 +261,15 @@ def __init__(self, master=None, **kw):
locale = kw.pop("locale", default_locale())
if locale is None:
locale = 'en'
self._day_names = get_day_names('abbreviated', locale=locale)
day_names = kw.pop('day_names', 'abbreviated')
self._day_names = get_day_names(day_names, locale=locale)
self._month_names = get_month_names('wide', locale=locale)
date_pattern = self._get_date_pattern(kw.pop("date_pattern", "short"), locale)

# --- date
today = self.date.today()

if self._textvariable is not None:
if self._textvariable is not None and self._textvariable.get() != '':
# the variable overrides day, month and year keywords
try:
self._sel_date = parse_date(self._textvariable.get(), locale)
Expand Down Expand Up @@ -311,6 +318,7 @@ def __init__(self, master=None, **kw):
raise ValueError("'selectmode' option should be 'none' or 'day'.")
# --- show week numbers
showweeknumbers = kw.pop('showweeknumbers', True)
weeknumberoffset = kw.pop('weeknumberoffset', 0)

# --- style
self.style = ttk.Style(self)
Expand All @@ -331,6 +339,7 @@ def __init__(self, master=None, **kw):
'maxdate',
'mindate',
'showweeknumbers',
'weeknumberoffset',
'showothermonthdays',
'firstweekday',
'weekenddays',
Expand All @@ -355,6 +364,7 @@ def __init__(self, master=None, **kw):
'headersforeground',
'disableddaybackground',
'disableddayforeground',
'day_names',
'tooltipforeground',
'tooltipbackground',
'tooltipalpha',
Expand All @@ -378,6 +388,7 @@ def __init__(self, master=None, **kw):
'mindate': mindate,
'maxdate': maxdate,
'showweeknumbers': showweeknumbers,
'weeknumberoffset': weeknumberoffset,
'showothermonthdays': kw.pop('showothermonthdays', True),
'selectbackground': active_bg,
'selectforeground': 'white',
Expand All @@ -400,6 +411,7 @@ def __init__(self, master=None, **kw):
'headersforeground': 'black',
'disableddaybackground': dis_bg,
'disableddayforeground': dis_fg,
'day_names': day_names,
'tooltipforeground': 'gray90',
'tooltipbackground': 'black',
'tooltipalpha': 0.8,
Expand Down Expand Up @@ -874,6 +886,7 @@ def _display_days_without_othermonthdays(self):
_, week_nb, d = self._date.isocalendar()
if d == 7 and self['firstweekday'] == 'sunday':
week_nb += 1
week_nb += self['weeknumberoffset']
modulo = max(week_nb, 52)
for i_week in range(6):
if i_week == 0 or cal[i_week][0][0]:
Expand Down