Skip to content

Setting 2025-01-01 and 2025-12-31 as mindate and maxdate in DateEntry disables selection of January and December dates in dropdown #115

@EGiesenROD

Description

@EGiesenROD

Hi,

I've encountered the following issue (I think it may be a bug). Setting 2025-01-01 and 2025-12-31 as mindate and maxdate in DateEntry disables selection of January and December dates in dropdown. This also appears to be an issue selecting dates further into 2026 for maxdate.

Minimal reproducible example (using v1.6.1):

import tkinter as tk
from tkcalendar import DateEntry
import pandas as pd

root = tk.Tk()
root.title("DateEntry Example")
root.geometry("250x100")

date_entry = DateEntry(
  root,
  width=12,
  background="darkblue",
  foreground="white",
  borderwidth=2
)

date_entry.pack(pady=20)
date_entry.configure(mindate=pd.Timestamp("2025-01-01"))
date_entry.configure(maxdate=pd.Timestamp("2026-12-31")) # Or 2025-12-31

root.mainloop()

Observed: January and December are entirely unselectable
Expected: All dates in 2025 selectable

I think the issue may be in the checks done to display the calendar, specifically lines 846-862.
Checking that the year and month match appears to fix this (but I have not tested this thoroughly).

      if maxdate is not None and maxdate.year == year and maxdate.month == month:
          mi, mj = self._get_day_coords(maxdate)
          if mi is not None:
              for j in range(mj + 1, 7):
                  self._calendar[mi][j].state(['disabled'])
              for i in range(mi + 1, 6):
                  for j in range(7):
                      self._calendar[i][j].state(['disabled'])

      if mindate is not None and mindate.year == year and mindate.month == month:
          mi, mj = self._get_day_coords(mindate)
          if mi is not None:
              for j in range(mj):
                  self._calendar[mi][j].state(['disabled'])
              for i in range(mi):
                  for j in range(7):
                      self._calendar[i][j].state(['disabled'])

Edit: indent code blocks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions