
In this post, we will see how to create a calendar using Python. We will learn 4 different methods to create calendar using Python. For all 4 programs, we will be using a famous module named calendar(inbuilt with Python). This module mimics the Georgian calendar. Two methods will be used to create text-based calendars and the last two methods will be GUI based. We will understand the programs using comments. Let’s start.
Creating text-based calendar of a year using Python
# importing calendar module import calendar # year of calendar, you can also take input from user=> int(input()) year = 2022 # printing calendar print(calendar.calendar(year))
Output:

Creating text-based calendar of a month using Python
# importing calendar module import calendar # year of calendar year = 2022 # month of calendar month = 10 # printing calendar print(calendar.month(year, month))
Output:

Now, to create GUI-based calendars, we will be using the Tkinter module.
Creating GUI-based calendar of a year using Python
# importing tkinter from tkinter import * # importing calendar module import calendar # initializing tkinter root = Tk() # setting title of our Gui root.title("My Own Gui Calendar") # year for which we want the calendar to be shown on our Gui year = 2022 # storing 2022 year calendar data inside myCal myCal = calendar.calendar(year) # showing calendar data using label widget cal_year = Label(root, text=myCal, font="Consolas 10 bold") # packing the Label widget cal_year.pack() # running the program in ready state root.mainloop()
Output:

Creating GUI-based calendar of a month using Python
# importing tkinter from tkinter import * # importing calendar module import calendar # initializing tkinter root = Tk() # setting title of our Gui root.title("My Own Gui Calendar") # year for which we want the calendar to be shown on our Gui year = 2022 # month of year month = 10 # storing 2022 year and 10th month calendar data inside myCal myCal = calendar.month(year, month) # showing calendar data using label widget cal_year = Label(root, text=myCal, font="Consolas 10 bold") # packing the Label widget cal_year.pack() # running the program in ready state root.mainloop()
Output:

Also Read:
- Radha Krishna using Python Turtle
- Yield Keyword in Python
- Python Programming Examples | Fundamental Programs in Python
- Python | Delete object of a class
- Python | Modify properties of objects
- Python classmethod
- Python | Create a class that takes 2 parameters, print both parameters
- Python | Create a class, create an object of the class, access, and print property value
- Python | Find the maximum element in a list using lambda and reduce()
- Python | filter numbers(that are not divisible by 3 and 4) from a list using lambda and filter()
- Python | lambda function that returns the maximum of 2 numbers
- Python | Convert all strings of a list to uppercase using lambda
- Python | Square numbers of a list using lambda
- Python | Reverse and convert a string to uppercase using lambda
- Python | Convert String to uppercase using lambda
- Python | Reverse a list using lambda
- Python | Calculator using lambda
- Python | Square of a number using lambda
- Python | Multiply numbers using lambda
- Python | lambda with None
- Python | lambda with pass statement
- Python | Add numbers using lambda
- Python | Print Namaste using lambda
- Iterate over a string in Python
- Python | join() | Join list of strings
- Python | isalnum() method | check if a string consists only of alphabetical characters or numerical digits
- Python | isupper() and islower() methods to check if a string is in all uppercase or lowercase letters
- Python | count substring in a String | count() method
- Python | enumerate() on String | Get index and element
- Python | Convert a String to list using list() method
Post Tags:
calendar in python
calendar program in python
calendar module in python
python calendar