This function is all the same as the one we used in the command line version of the app the only difference here is that in the try statement, we are getting the day, month, and year from the entries using the get() function and also in the except statement, all errors that the app will catch will be displayed on the showerror popup window. 'Make sure you enter valid data and fill all the fields') # convering year, month and day into birthdateĪge = today.year - birthdate.year - ((today.month, today.day) Invalid input data\n->An empty field/fields\n'\ # we are getting the current date using the today() Just below the import, paste these lines of code: # defining the for calculating the age, the function takes day We will now create a function for calculating the age we will call it calculate_age(). Here we are importing date from datetime, this module provides several functions and classes for handling dates and times. Now that the environment is all set, open the age_calculator_cli.py file, and do the following import: from datetime import date Related: How to Make a Calculator with Tkinter in Python. You can call them anything per your preference make sure the file names are meaningful. Implementing the Age Calculation Functionalityįirst things first, let us set up the environment, create two new Python files and call them age_calculator_cli.py and age_calculator_ui.py:.We will build all these from the ground up. In the first section, we will build a command line version, and finally, in the second section, we will make a GUI version of the app. This article has been split into two sections. If you have fancied the idea of building your own age calculator app using Python, then you are at the right place because this article is just for you.īefore we dive deeper into this article, let us first understand what an age calculator app is this app calculates the user's age using their birth date (day, month, and year).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |