Hello, I want to teach you to make a calendar with Python language programming,
Background
In my case I want to make a simple GUI for an app that need a calendar to see and maintain that app.
Getting started
To do that we need a library python which is name is "Tkinter". lets we do it first you must import from tkinter import *
as you know, Tkinter is the built-in library in python, so you don't need to install them, you can just call them in command import as above. and the next step is basic standard code to run Tkinter, you can follow this code to run Tkinter.
from tkinter import *
window = Tk()
window.title("Welcome to Helloworld app") #this for your title
width = 400 #this is for the width size of the window
height = 400 #this is for the height size of the window
x = 500 #this is the distance your window with the border screen of your laptop/PC from up and down
y = 200 #this is the distance between your window with your border screen of the laptop/PC from left and right
window.geometry(f"{width}x{height}+{x}+{y}") #this for size window
window.mainloop() #this to run your tkinter
this is the first step you can run your Tkinter, it opened as you run it, but not done yet because it's empty in your window. We can fill it with code to make a calendar. now the next step you can add import from tkcalendar import *
or if you don't have this you can install it with this command pip install tkcalendar
on your terminal.
And then, we can input the code like this,
from tkinter import *
from tkcalendar import *
window = Tk()
window.title("Welcome to Helloworld app")
width = 400
height = 400
x = 500
y = 200
window.geometry(f"{width}x{height}+{x}+{y}")
def date_picker():
date = myCal.get_date()
date_label = Label(window, text="This date is" + date)
date_label.grid(row=7, column=1, ipadx=10, ipady=10, sticky="wesn", pady=10)
myCal = Calendar(window, selectmode="day", date_pattern="dd/mm/yyyy", )
myCal.grid(row=0, column=0, columnspan=3, rowspan=5, sticky="wesn", pady=50)
OpenCal = Button(window, text="Select Date", command=date_picker)
OpenCal.grid(row=6, column=1, ipadx=10, ipady=10, sticky="wesn", pady=10)
window.mainloop()
I add widget button and function date_picker
to get data of date in calendar, so we can see the result on below
we can see if we chose date on calendar and click the button, we can get the date on label column.
okay thanks for your read, see you in the next post :)
Github :https://github.com/Hendra-Kusuma
Email : hendrakusuma.vegas@gmail.com
Top comments (0)