Python | GUI Calendar using Tkinter

1348 views

Hope you are doing great!

Today we are going to make a python program to create GUI Calendar Using Python.

To create GUI Calendar Using Python, we will need to import two Python modules one for creating GUI and another to get year data.

For GUI we will use "tkinter module" because it’s very easy to learn and use.

And to get any year data we will use "calendar module".

To install tkinter and calendar module , go to terminal and type,

pip install tkinter
Code language: Python (python)
pip install calendar module
Code language: Python (python)

Code with comments: GUI calendar using Python

from tkinter import * import tkinter as tk from PIL import ImageTk, Image import calendar root = tk.Tk() root.geometry('400x300') root.title('Calender-Techarge') root.iconbitmap("calender-ico.ico") def show(): m = int(month.get()) y = int(year.get()) output = calendar.month(y,m) cal.insert('end',output) def clear(): cal.delete(1.0,'end') def exit(): root.destroy() img = ImageTk.PhotoImage(Image.open('calendar.png')) label = Label(image=img) label.place(x=170,y=3) m_label = Label(root,text="Month",font=('verdana','10','bold')) m_label.place(x=70,y=80) month = Spinbox(root, from_= 1, to = 12,width="5") month.place(x=140,y=80) y_label = Label(root,text="Year",font=('verdana','10','bold')) y_label.place(x=210,y=80) year = Spinbox(root, from_= 2020, to = 3000,width="8") year.place(x=260,y=80) cal = Text(root,width=33,height=8,relief=RIDGE,borderwidth=2) cal.place(x=70,y=110) show = Button(root,text="Show",font=('verdana',10,'bold'),relief=RIDGE,borderwidth=2,command=show) show.place(x=140,y=250) clear = Button(root,text="Clear",font=('verdana',10,'bold'),relief=RIDGE,borderwidth=2,command=clear) clear.place(x=200,y=250) exit = Button(root,text="Exit",font=('verdana',10,'bold'),relief=RIDGE,borderwidth=2,command=exit) exit.place(x=260,y=250) root.mainloop()# 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 = 2020 # storing 2020 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()
Code language: Python (python)

Here, we have made a very simple and short program, but you can make this GUI application more user friendly like you can add entry widgets to get the year during the run time and show the specific year’s calendar by clicking on a button.

In case, you don’t know how to create your GUI application more friendly or how to add more functionalities to your GUI application read more at https://docs.python.org/3/library/tk.html

ThankYou Pythoner’s!!!

Check out more python projects

You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More

Enable Notifications    OK No thanks