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:
- Python | Check Armstrong Number using for loop
- Python | Factorial of a number using for loop
- Python | Asking the user for input until they give a valid response
- Python | How to iterate through two lists in parallel?
- Python | How to sort a dictionary by value?
- Python | Remove items from a list while iterating
- Python | How to get dictionary keys as a list
- How to represent Enum in Python?
- 5 methods | Flatten a list of lists | Convert nested list into a single list in Python
- What does if __name__ == __main__ do in Python?
- Python | CRUD operations in MongoDB
- Create your own ChatGPT with Python
- Filter List in Python | 10 methods
- 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
Post Tags:
calendar in python
calendar program in python
calendar module in python
python calendar