Skip to content

Commit 9f6df89

Browse files
authored
Update main.py
Add `mycalendar.DateEntry`
1 parent 5bd61ea commit 9f6df89

1 file changed

Lines changed: 41 additions & 13 deletions

File tree

  • tkinter/tkcalendar - add allowed_dates
Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,56 @@
1+
#!/usr/bin/env python3.13
2+
3+
# date: 2025.08.06
4+
5+
# [python - Restrict date selection from calendar to specific dates - Stack Overflow](https://stackoverflow.com/questions/79727284/restrict-date-selection-from-calendar-to-specific-dates)
6+
7+
import datetime as dt
8+
import tkinter as tk
9+
from tkinter import ttk
10+
#from tkcalendar import DateEntry
11+
12+
from mycalendar import Calendar
13+
from mycalendar import DateEntry
14+
15+
# fmt: off
16+
dates = [
17+
"2024-04-08", "2024-04-10", "2024-04-11", "2024-04-12",
18+
"2024-04-15", "2024-04-16", "2024-04-17", "2024-04-18", "2024-04-19",
19+
"2024-04-22",
20+
"2024-05-21", "2024-05-22", "2024-05-23", "2024-05-24",
21+
"2024-05-27", "2024-05-28", "2024-05-29", "2024-05-30", "2024-05-31",
22+
"2024-06-03", "2024-06-04", "2024-06-05", "2024-06-07",
23+
"2024-06-10", "2024-06-11", "2024-06-12", "2024-06-13", "2024-06-14",
124
]
225
# fmt: on
326

427
root = tk.Tk()
528

629
dt_dates = [ dt.date.fromisoformat(date) for date in dates ]
730

8-
cal = mycalendar.Calendar(
31+
# example mycalendar.Calendar
32+
cal = Calendar(
933
root,
1034
date_pattern="yyyy-mm-dd",
11-
mindate=dt.date.fromisoformat(dates[0]),
12-
maxdate=dt.date.fromisoformat(dates[-1]),
35+
mindate=dt_dates[0],
36+
maxdate=dt_dates[-1],
1337
allowed_dates=dt_dates,
14-
locale="en_GB.utf-8", # to show it in English instead of my native Polish
38+
#locale="en_GB.utf-8", # to show it in English instead of my native Polish
39+
# to make screenshot
1540
)
1641
cal.pack()
1742

18-
#date_entry_var = tk.StringVar()
19-
#date_entry = DateEntry(
20-
# root,
21-
# textvariable=date_entry_var,
22-
# date_pattern="yyyy-mm-dd",
23-
# mindate=dt.date.fromisoformat(dates[0]),
24-
# maxdate=dt.date.fromisoformat(dates[-1]),
25-
#)
26-
#date_entry.pack()
43+
date_entry_var = tk.StringVar()
44+
45+
# example mycalendar.DateEntry
46+
date_entry = DateEntry(
47+
root,
48+
textvariable=date_entry_var,
49+
date_pattern="yyyy-mm-dd",
50+
mindate=dt_dates[0],
51+
maxdate=dt_dates[-1],
52+
allowed_dates=dt_dates,
53+
)
54+
date_entry.pack()
2755

2856
root.mainloop()

0 commit comments

Comments
 (0)