Python PyQt5 GUI Birthday Age Calculator with Calendar Widget Desktop App Full Project For Beginners

Python PyQt5 GUI Birthday Age Calculator with Calendar Widget Desktop App Full Project For Beginners


Welcome folks today in this post we will be building a birthday age calculator gui desktop app using pyqt5 in python. All the full source code of the application is given below.



Get Started



In order to get started you need to install the following library using the pip command as shown below


pip install pyqt5


After installing this library we need to make an file and copy paste the following code



# importing libraries 
from PyQt5.QtWidgets import *
from PyQt5 import QtCore, QtGui 
from PyQt5.QtGui import *
from PyQt5.QtCore import *
import datetime 
import sys 

class Window(QMainWindow): 

    def __init__(self): 

        # setting title 
        self.setWindowTitle("Python ") 

        # width of window 
        self.w_width = 400

        # height of window 
        self.w_height = 500

        # setting geometry 
        self.setGeometry(100, 100, self.w_width, self.w_height) 

        # calling method 

        # showing all the widgets 

    # method for components 
    def UiComponents(self): 

        # creating head label 
        head = QLabel("Age Nearest Birthday Calculator", self) 


        # setting geometry to the head 
        head.setGeometry(0, 10, 400, 60) 

        # font 
        font = QFont('Times', 15) 

        # setting font to the head 

        # setting alignment of the head 

        # setting color effect to the head 
        color = QGraphicsColorizeEffect(self) 

        # creating a label 
        b_label = QLabel("Select Birthday", self) 

        # setting properties label 
        b_label.setGeometry(50, 105, 300, 25) 
                            "border : 1px solid black;"
                            "background : rgba(70, 70, 70, 25);"
        b_label.setFont(QFont('Times', 9)) 

        # creating a calendar widget to select the date 
        self.calendar = QCalendarWidget(self) 

        # setting geometry of the calendar 
        self.calendar.setGeometry(50, 130, 300, 180) 

        # setting font to the calendar 
        self.calendar.setFont(QFont('Times', 6)) 

        # getting current date 
        date = QDate.currentDate() 

        # blocking future dates 

        # creating a push button 
        calculate = QPushButton("Calculate Time", self) 

        # setting geometry to the push button 
        calculate.setGeometry(125, 340, 150, 40) 

        # adding action to the calculate button 

        # creating a label to show percentile 
        self.result = QLabel(self) 

        # setting properties to result label 
        self.result.setGeometry(50, 400, 300, 60) 
                                "border : 3px solid black;"
                                "background : white;"
        self.result.setFont(QFont('Arial', 11)) 

    def calculate_action(self): 

        # getting birth date day 
        birth = self.calendar.selectedDate() 

        # getting year and month day of birth day 
        birth_year = birth.year() 
        birth_month = birth.month() 
        birth_day = 

        # getting today date 
        current = QDate.currentDate() 

        # getting year and month day of current day 
        current_year = current.year() 
        current_month = current.month() 
        current_day = 

        # coverting dates into date object 
        birth_date =, birth_month, birth_day) 
        current_date =, current_month, current_day) 

        # getting difference in both the dates 
        difference = current_date - birth_date 

        # getting days from the difference 
        difference = difference.days 

        # getting years from the difference 
        years = difference / 365.2422

        # getting round value of years 
        years = round(years) 

        # setting this value with the help of label 
        self.result.setText("Closest Age is : " + str(years)) 

# create pyqt5 app 
App = QApplication(sys.argv) 

# create the instance of our Window 
window = Window() 

# start the app 


See also  Python 3 Carbon Source Code Snippet Generator and Download as PNG File with Beautiful Themes and Colors Script Full Project For Beginners


Now just execute the above script by typing the below command as shown below






Leave a Reply