Create a Date Picker Calendar in Tkinter


Tkinter is a popular Python library for creating and developing applications. It has various methods and functions that can be used for adding multiple features in an application.

Tkcalendar is one of the tkinter packages that can be used to create GUI-based calendars in the window and thus, we can perform multiple operations like selecting the data, picking and scheduling the event through the calendar application and many more.

However, in this article, we will see how we can create a Date Picker calendar using the Tkcalendar package. Before that, we have to install the package in our local environment using pip install tkcalendar.

Once installed, we will create an instance of tkcalendar and create a button to get the date.

Example

#Import the libraries
from tkinter import *
from tkcalendar import *

#Create an instance of tkinter frame or window
win= Tk()
win.title("Calendar")
win.geometry("700x600")

cal= Calendar(win, selectmode="day",year= 2021, month=3, day=3)
cal.pack(pady=20)

#Define Function to select the date
def get_date():
   label.config(text=cal.get_date())

#Create a button to pick the date from the calendar
button= Button(win, text= "Select the Date", command= get_date)
button.pack(pady=20)

#Create Label for displaying selected Date
label= Label(win, text="")
label.pack(pady=20)

win.mainloop()

Output

Running the above code will create a calendar, where we can select a particular date.

Updated on: 04-Mar-2021

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements