
Introduction
In the digital age, calendars play a vital role in helping us manage our schedules and stay organized. In this article, you will learn how to Create a Calendar App using Python tkinter which displays simultaneous calendars with dates, months, and years in a beautiful form.
Tkinter is a popular GUI toolkit that offers a fantastic library called TkCalendar. TkCalendar provides a simple way to build a custom calendar with various features.
Requirements
Before you start, make sure you have Python installed on your system. You can install the latest version from their website (https://www.python.org/). Additionally, youāll need to install the Tkinter (Documentation) and TkCalendar libraries. You can do this by running the following command:
pip install tkinter tkcalendar
Importing the Necessary Libraries
First, letās import the required libraries into our Python script:
import tkinter as tk from tkcalendar import Calendar
Creating the Calendar App
Now, weāll create a basic Tkinter window that will serve as the main interface for our calendar app:
root = tk.Tk() root.title("Calendar App") root.geometry("400x400")
Here, weāve created a window titled āCalendar Appā and set its dimensions to 400Ć400 pixels. You can adjust the dimensions according to your preferences.
Adding the Calendar Widget
Next, weāll add the TkCalendar widget to our application. This widget will display the calendar and allow you to select dates:
cal = Calendar(root, selectmode="day", date_pattern="yyyy-mm-dd") cal.pack(pady=20)
In the above code, weāve created an instance of the Calendar widget called ācalā and configured it to allow the selection of a single day at a time (āselectmode=ādayāā). The ādate_patternā parameter specifies the format in which the selected date will be displayed.
Displaying the Selected Date
To display the selected date, letās add a label widget to our application:
selected_date = tk.Label(root, text="") selected_date.pack(pady=10)
Here, weāve created a label widget called āselected_dateā that will show the chosen date. Initially, itās left blank, but weāll update it dynamically based on user selection.
Updating the Selected Date
To update the selected date whenever a new date is chosen, weāll define a function and bind it to the calendar widget:
def update_selected_date(): selected_date.config(text="Selected Date: " + cal.get_date()) cal.bind("<<CalendarSelected>>", lambda event: update_selected_date())
The āupdate_selected_dateā function retrieves the selected date using ācal.get_date()ā and updates the selected_date label accordingly. We bind this function to the ā<<CalendarSelected>>ā event of the calendar widget, ensuring that it triggers whenever a new date is chosen.
Running the Application
Finally, weāll add the main event loop, which keeps the application running until itās closed:
root.mainloop()
Putting It All Together
Hereās the complete code for our calendar app:
import tkinter as tk from tkcalendar import Calendar def update_selected_date(): selected_date.config(text="Selected Date: " + cal.get_date()) root = tk.Tk() root.title("Calendar App") root.geometry("400x400") cal = Calendar(root, selectmode="day", date_pattern="yyyy-mm-dd") cal.pack(pady=20) selected_date = tk.Label(root, text="") selected_date.pack(pady=10) cal.bind("<<CalendarSelected>>", lambda event: update_selected_date()) root.mainloop()
Output
The program outputs the following:

For any queries or feedback, share your thoughts in the comments below. I would love to hear from you!
If you want more lovely Tkinter Examples like this, visit our separate page packed with Various Python Projects. Here are a few examples to spark your interest:
- Create a Typing Speed Tester in Python with Tkinter
- Create a Language Translator App in Python using Tkinter
- Create an Alarm Clock using Python with Tkinter
- Create a Countdown Timer in Python with Start and Pause
Happy Coding!