Skip to content

Commit

Permalink
Add ability to set a specific year, month, or day as part of the cons…
Browse files Browse the repository at this point in the history
…tructor.
  • Loading branch information
slightlynybbled committed Apr 9, 2021
1 parent 277c01e commit 7a31da6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
4 changes: 3 additions & 1 deletion examples/user_calendar.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from datetime import datetime

import tkinter
import tk_tools
import locale
Expand All @@ -19,7 +21,7 @@ def callback():
if show_in_german:
locale.setlocale(locale.LC_ALL, 'deu_deu')

calendar = tk_tools.Calendar(root)
calendar = tk_tools.Calendar(root, year=2021, month=2, day=5)
calendar.pack()

calendar.add_callback(callback)
Expand Down
18 changes: 13 additions & 5 deletions tk_tools/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,21 +513,29 @@ class Calendar(ttk.Frame):
:param parent: the parent frame
:param callback: the callable to be executed on selection
:param kw: tkinter.frame keyword arguments
:param year: the year as an integer, i.e. `2020`
:param month: the month as an integer; not zero-indexed; i.e.
"1" will translate to "January"
:param day: the day as an integer; not zero-indexed
:param kwargs: tkinter.frame keyword arguments
"""
timedelta = datetime.timedelta
datetime = datetime.datetime

def __init__(self, parent, callback: callable = None, **kwargs):
def __init__(self, parent, callback: callable = None,
year: int = None, month: int = None, day: int = None,
**kwargs):
# remove custom options from kw before initializing ttk.Frame
fwday = calendar.SUNDAY
year = kwargs.pop('year', self.datetime.now().year)
month = kwargs.pop('month', self.datetime.now().month)
now = self.datetime.now()
year = year if year else now.year
month = month if month else now.month
day = day if day else now.day
locale = kwargs.pop('locale', None)
sel_bg = kwargs.pop('selectbackground', '#ecffc4')
sel_fg = kwargs.pop('selectforeground', '#05640e')

self._date = self.datetime(year, month, 1)
self._date = self.datetime(year, month, day)
self._selection = None # no date selected
self.callback = callback

Expand Down
2 changes: 1 addition & 1 deletion tk_tools/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.13.0'
__version__ = '0.14.0'

0 comments on commit 7a31da6

Please sign in to comment.