Skip to content

Commit 7a31da6

Browse files
Add ability to set a specific year, month, or day as part of the constructor.
1 parent 277c01e commit 7a31da6

3 files changed

Lines changed: 17 additions & 7 deletions

File tree

examples/user_calendar.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from datetime import datetime
2+
13
import tkinter
24
import tk_tools
35
import locale
@@ -19,7 +21,7 @@ def callback():
1921
if show_in_german:
2022
locale.setlocale(locale.LC_ALL, 'deu_deu')
2123

22-
calendar = tk_tools.Calendar(root)
24+
calendar = tk_tools.Calendar(root, year=2021, month=2, day=5)
2325
calendar.pack()
2426

2527
calendar.add_callback(callback)

tk_tools/groups.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -513,21 +513,29 @@ class Calendar(ttk.Frame):
513513
514514
:param parent: the parent frame
515515
:param callback: the callable to be executed on selection
516-
:param kw: tkinter.frame keyword arguments
516+
:param year: the year as an integer, i.e. `2020`
517+
:param month: the month as an integer; not zero-indexed; i.e.
518+
"1" will translate to "January"
519+
:param day: the day as an integer; not zero-indexed
520+
:param kwargs: tkinter.frame keyword arguments
517521
"""
518522
timedelta = datetime.timedelta
519523
datetime = datetime.datetime
520524

521-
def __init__(self, parent, callback: callable = None, **kwargs):
525+
def __init__(self, parent, callback: callable = None,
526+
year: int = None, month: int = None, day: int = None,
527+
**kwargs):
522528
# remove custom options from kw before initializing ttk.Frame
523529
fwday = calendar.SUNDAY
524-
year = kwargs.pop('year', self.datetime.now().year)
525-
month = kwargs.pop('month', self.datetime.now().month)
530+
now = self.datetime.now()
531+
year = year if year else now.year
532+
month = month if month else now.month
533+
day = day if day else now.day
526534
locale = kwargs.pop('locale', None)
527535
sel_bg = kwargs.pop('selectbackground', '#ecffc4')
528536
sel_fg = kwargs.pop('selectforeground', '#05640e')
529537

530-
self._date = self.datetime(year, month, 1)
538+
self._date = self.datetime(year, month, day)
531539
self._selection = None # no date selected
532540
self.callback = callback
533541

tk_tools/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.13.0'
1+
__version__ = '0.14.0'

0 commit comments

Comments
 (0)