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
20 changes: 18 additions & 2 deletions tkcalendar/calendar_.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,10 +492,13 @@ def __init__(self, master=None, **kw):

self.config(state=state)

self._theme_name = None
self._setup_style()

# --- bindings
self.bind('<<ThemeChanged>>', self._setup_style)
self.theme_change_cbid = None
self.bind('<<ThemeChanged>>', self.schedule_style_update)

self._setup_style()
self._display_calendar()
self._btns_date_range()
self._check_sel_date()
Expand Down Expand Up @@ -746,6 +749,18 @@ def _textvariable_trace(self, *args):
self._display_calendar()
self._display_selection()

def schedule_style_update(self, event=None):
if self.theme_change_cbid is None:
self.theme_change_cbid = self.after(10, self._on_theme_change)

def _on_theme_change(self):
theme = self.style.theme_use()
if self._theme_name != theme:
# the theme has changed, update the DateEntry style to look like a combobox
self._theme_name = theme
self._setup_style()
self.theme_change_cbid = None

def _setup_style(self, event=None):
"""Configure style."""
self.style.layout('L.%s.TButton' % self._style_prefixe,
Expand Down Expand Up @@ -819,6 +834,7 @@ def _setup_style(self, event=None):
self.style.map(self._style_prefixe + '.TLabel',
background=[('disabled', dis_day_bg)],
foreground=[('disabled', dis_day_fg)])
self._theme_name = self.style.theme_use()

# --- display
def _display_calendar(self):
Expand Down
10 changes: 8 additions & 2 deletions tkcalendar/dateentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ def __init__(self, master=None, **kw):

# --- bindings
# reconfigure style if theme changed
self.bind('<<ThemeChanged>>',
lambda e: self.after(10, self._on_theme_change))
self.theme_change_cbid = None
self.bind('<<ThemeChanged>>', self.schedule_style_update)
# determine new downarrow button bbox
self.bind('<Configure>', self._determine_downarrow_name)
self.bind('<Map>', self._determine_downarrow_name)
Expand All @@ -181,6 +181,10 @@ def __getitem__(self, key):
def __setitem__(self, key, value):
self.configure(**{key: value})

def schedule_style_update(self, event=None):
if self.theme_change_cbid is None:
self.theme_change_cbid = self.after(10, self._on_theme_change)

def _setup_style(self, event=None):
"""Style configuration to make the DateEntry look like a Combobbox."""
self.style.layout('DateEntry', self.style.layout('TCombobox'))
Expand All @@ -202,6 +206,7 @@ def _setup_style(self, event=None):
# nothing to cancel
pass
self._determine_downarrow_name_after_id = self.after(10, self._determine_downarrow_name)
self._theme_name = self.style.theme_use()

def _determine_downarrow_name(self, event=None):
"""Determine downarrow button name."""
Expand Down Expand Up @@ -237,6 +242,7 @@ def _on_theme_change(self):
# the theme has changed, update the DateEntry style to look like a combobox
self._theme_name = theme
self._setup_style()
self.theme_change_cbid = None

def _on_b1_press(self, event):
"""Trigger self.drop_down on downarrow button press and set widget state to ['pressed', 'active']."""
Expand Down