Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

In Python, we can use Tkinter to make guIs. If you are very imaginative and creative, you can make a lot of interesting things with Tkinter. Here, we’ll make a Python calendar GUI application using Tkinter. In this application, the user must enter the year you want to view the calendar before it appears.

🏆 Use Tkinter’s calendar GUI application

This article is a series of three introductory Python projects. Beginners can try implementing these projects and get their hands dirty in a Python compilation environment.

🌟 [Python Introduction Project] Generate QR codes using Python 🌟 Use Tkinter’s Python calendar GUI application 🌟 use Python to convert images into pencil sketches

Step 1: Install Tkinter

First install Tkinter using the following command:

pip install tk
Copy the code

We also need a calendar package, but we don’t have to install it; it’s the default package that comes with Python.

Step 2: Import the module

First import the Calendar module and the Tkinter module

import calendar
from tkinter import *
Copy the code

Step 3: Display the calendar for the given year

The following function displays the calendar for the given year

def showCalender() :
    gui = Tk()
    gui.config(background='grey')
    gui.title("Calender for the year")
    gui.geometry("550x600")
    year = int(year_field.get())
    gui_content= calendar.calendar(year)
    calYear = Label(gui, text= gui_content, font= "Consolas 10 bold")
    calYear.grid(row=5, column=1,padx=20)
    gui.mainloop()
Copy the code

instructions

The ShowCalender function is displaying a calendar. This is where you manage the display of the calendar when you Enter a year in the search box and press Enter. You can set the gray background color here, and you can change it in the code as needed. You can also set the size of the calendar to 550 x 600 here. You then ask for the year to be entered as an integer. Once the user enters the year calendar content, it is retrieved from Python’s calendar module by taking the year as an argument.

Step 4: Set up the driver code

Here is the driver code

if __name__=='__main__':
    new = Tk()
    new.config(background='grey')
    new.title("Calender")
    new.geometry("250x140")
    cal = Label(new, text="Calender",bg='grey',font=("times".28."bold"))
    Enter a label for the year
    year = Label(new, text="Enter year", bg='dark grey')
    # Year enter text box
    year_field=Entry(new)
    button = Button(new, text='Show Calender',fg='Black',bg='Blue',command=showCalender)
Copy the code

Adjust the position of the widgets

    cal.grid(row=1, column=1)
    year.grid(row=2, column=1)
    year_field.grid(row=3, column=1)
    button.grid(row=4, column=1)
    Exit.grid(row=6, column=1)
    new.mainloop()
Copy the code

instructions

In the driver code, first we provide the background color for the left side of the screen (as shown below). Because the window giving the input year is small, we set the size to 250×140. In the button line below year_field, we call the showCalendar function created above. This function shows us the complete calendar for the entered year.

Now we also need to adjust the widget in the calendar, for which we define the location of everything in the grid. You can explore more by changing grid row and column parameters.

Step 5: Output the calendar GUI

Although the style is ugly, but as a novice to make such a small program or a little sense of achievement.

🛬 wuhu! Take off!

This will be followed by the Python applets you made:

  • Convert images to pencil sketches using Python

I’ve been writing technical blogs for a long time, mostly through Nuggets, and this is my tutorial on a Python applet. I like to share technology and happiness through articles. You can visit my blog at juejin.cn/user/204034… For more information. Hope you like it! 😊

🥇 past quality articles

❤️ Single-player AI minesweeper using Python ❤️ [Python Introduction Project] Generate qr codes using Python ❤️ Simple analog clock ❤️ using HTML, CSS and JavaScript Make a random password generator ❤️ Make a great weather Web application using HTML, CSS, JS and API ❤️ Are you really proficient with HTML5 and how many of these 10 cool H5 features do you know? ❤️ how to design a Neumorphism style digital clock in JavaScript

💌 welcomes your comments and suggestions in the comments section! 💌

If you really learn something new from this article, like it, bookmark it and share it with your friends. 🤗 and finally, don’t forget ❤ or 📑.