In this article we will see how we can create calculator which tells how many seconds a person has lived. Below si how the calculator will look like
Concept : We can get the age in seconds by getting the difference between the birth date and the birth time with the present date and time with the help of python datetime objects, which will keep count of leap years and we can get the number of days and seconds between the dates. Then these days can be converted into seconds to get the total seconds count.
GUI Implementation Steps :
1. Create a heading label that display the calculator name
2. Create label to show user to select the birth date and the birth time
3. Create a QCalendarWidget object for user to select the birth date
4. Create a QTimeEdit object to get the birth time
5. Create a push button to calculate the age in seconds
6. Create a label to show the calculated age in seconds
Back-End Implementation :
1. Make the calendar future date block i.e set current date as maximum date
2. Add action to the push button
3. Inside the push button action get the date from the calendar and time from the QTimeEdit
4. Get the day, month and year from the date and hour and minute from the time edit
5. Create a datetime object for current date and the birth date
6. Get the difference from both the dates and get the days and seconds
7. Convert days into seconds and add it to the original seconds
8. Show the calculated seconds value through 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.