
import tkinter as tk
from tkinter import ttk
from tkcalendar import Calendar
from datetime import date
my_w = tk.Tk()
my_w.geometry("380x220")
dt = date.today() # today
dt1=date(2021,8,3) # specific date Year, month , day
dt2=date(2021,8,25) # Maximum date in Year, month , day
cal=Calendar(my_w,selectmode='day',mindate=dt1,maxdate=dt2)
cal.grid(row=1,column=1,padx=15)
my_w.mainloop()
import tkinter as tk
from tkcalendar import Calendar
from datetime import datetime
my_w = tk.Tk()
my_w.geometry("320x210")
date_today = datetime.now() # today's date
cal=Calendar(my_w,selectmode='day', mindate=date_today)
cal.grid(row=1,column=1,padx=15)
my_w.mainloop()
We can disable selection of all future dates by using maxdate option
cal=Calendar(my_w,selectmode='day', maxdate=date_today)
from datetime import timedelta,date,datetime
dt = date.today() + timedelta(days=1) # Tomorrow
cal=Calendar(my_w,selectmode='day',maxdate=dt)
Select all days starting from yesterday
dt = date.today() + timedelta(days=-1) # Yesterday
cal=Calendar(my_w,selectmode='day',mindate=dt)
from dateutil.relativedelta import relativedelta
from datetime import date
dt = date.today() + relativedelta(days=1))# tomorrow
Check how future dates are enabled using relativedelta.
import tkinter as tk
from tkcalendar import Calendar
from dateutil.relativedelta import relativedelta
from datetime import date
my_w = tk.Tk()
my_w.geometry("320x210")
dt = date.today() + relativedelta(years=1,months=2,days=3)
cal=Calendar(my_w,selectmode='day',maxdate=dt,mindate=date.today())
cal.grid(row=1,column=1,padx=15)
my_w.mainloop()
import tkinter as tk
from tkinter import ttk
from tkcalendar import Calendar
from datetime import timedelta,date,datetime
my_w = tk.Tk()
my_w.geometry("380x220")
sel=tk.StringVar()
def my_upd(*args): # triggered when value of string varaible changes
dt1=cal.selection_get() # minmum date
dt2=dt1 + timedelta(days=10) # maximum date, added 10 days
cal.config(mindate=dt1) # set minimum date
cal.config(maxdate=dt2) # set maximum date
cal=Calendar(my_w,selectmode='day',textvariable=sel)
cal.grid(row=1,column=1,padx=15)
b1=tk.Button(my_w,text='Reset'
,command=lambda:cal.config(mindate=None,maxdate=None))
b1.grid(row=2,column=1)
sel.trace('w',my_upd) # on change of string variable
my_w.mainloop()
days_gap=10 #Minimum gap to be maintained
end_date=15 #Within this range 2nd does to be taken
def my_upd(*args): # triggered when value of string varaible changes
dt1=cal.selection_get() + timedelta(days=days_gap) # Start for 2nd dose
dt2=dt1 + timedelta(days=end_date) # end date for 2nd dose
cal.config(mindate=dt1) # set minimum date
cal.config(maxdate=dt2) # set maximum date
Read the list of formats used in displaying Date and time tkcalendar DateEntry
Projects in Tkinter
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.