In this article we will see how we can create an age calculator using PyQt5.
PyQt5 is cross-platform GUI toolkit, a set of python bindings for Qt v5. One can develop an interactive desktop application with so much ease because of the tools and simplicity provided by this library. It has to be installed using command given below
pip install PyQt5
Below is how age calculator will look like
GUI Implementation Steps :
1. Create a head label for the title of the game, set its properties
2. Create a date of birth label, below this label create QDateEdit object to receive the date and set their properties
3. Create a given date label, below this label create QDateEdit object to receive the new date and set their properties
4. Create a push button which when pressed date is calculated
5. Create result label to show the result i.e calculated age
Back-End implementation Steps :
1. Add action to the first QDateEdit when date is changed
2. Inside the first date edit action get the date of second date edit and set this date as maximum date of the first date edit
3. Add action to the second date edit when date is changed
4. Inside the second date edit action get the date of the first date edit and set this date as minimum date of the second date edit
5. Set different to the date edits such that first date should be less than second date
6. Add action to the push button
7. Inside the push button action, get the dates from both the date edits and calculate the difference and show the difference to the screen with the help of result label
Below is the implementation
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.