Python Tkinter Age Calculator

In this tutorial, we will learn about how to create s Python Tkinter Age Calculator in Python. In this application, we will see the user can enter their date of birth and the calculator automatically calculate the age of the person. How old the person just simply type their date of birth and the calculated tell the exact age.

Python Tkinter age calculator

Block of code:

In this block of Python Tkinter Age Calculator block of code, we simply import some libraries from which we can create an application Age Calculator.

With the help of this application, the calculator can calculate the get just simply typing the date of birth in the entry box.

from tkinter import *
import datetime
import tkinter as tk
from PIL import Image,ImageTk

Block of code:

In this Python Tkinter Age Calculator block of code, we will create a workspace where the calculator can calculate the age of the Person.

  • wd.geometry(“400×400”) is used to give the width and height to the window.
  • wd.title(“Pythontpoint”) is used to give a title to the window.
  • nameofperson = tk.Label(text = “Name”) is used to give label as name.
  • nameofperson.grid(column=0,row=1) is used to create the grid for name.
  • year = tk.Label(text = “Year”) is used to give a label as year.
  • year.grid(column=0,row=2) is used to create the grid for the year.
  • date = tk.Label(text = “Day”) is used to give a date as a label.
  • date.grid(column=0,row=4) is used to create a grid for date.
  • nameofpersonEntry = tk.Entry() is used to create the entry box for name.
  • nameofpersonEntry.grid(column=1,row=1) is used is used to create the entry box grid.
  • yearentry = tk.Entry() is used to create the year entry box.
  • yearentry.grid(column=1,row=2) is used to create the year entry grid.
  • monthentry = tk.Entry() is used to create the month entry.
  • monthentry.grid(column=1,row=3) is used to create month entry grid.
  • dateentry = tk.Entry() is used to create the date entry box.
  • dateentry.grid(column=1,row=4) is used to create the date entry grid.
wd=tk.Tk()
wd.geometry("400x400")
wd.title("Pythontpoint")
nameofperson = tk.Label(text = "Name")
nameofperson.grid(column=0,row=1)
year = tk.Label(text = "Year")
year.grid(column=0,row=2)
month = tk.Label(text = "Month")
month.grid(column=0,row=3)
date = tk.Label(text = "Day")
date.grid(column=0,row=4)
nameofpersonEntry = tk.Entry()
nameofpersonEntry.grid(column=1,row=1)
yearentry = tk.Entry()
yearentry.grid(column=1,row=2)
monthentry = tk.Entry()
monthentry.grid(column=1,row=3)
dateentry = tk.Entry()
dateentry.grid(column=1,row=4)

Block of code:

In this Python Tkinter Age Calculator block of code, we will create an entry box for all the labels in which users can enter the input.

  • nameofperson=nameofpersonEntry.get() is used to get the name as the input from the user.
  • dog=Person(nameofperson,datetime.date(int(yearentry.get()),int(monthentry.get()),int(dateentry.get()))) is used to get the month as a input from the user.
  • textArea = tk.Text(master=wd,height=10,width=25) is used where the text is created.
  • textArea.grid(column=1,row=6) is used as a text grid.
  • textArea.insert(tk.END,answer) is used to insert in the text area.
  • button=tk.Button(wd,text=”Calculate Age Of Person”,command=getinput,bg=”cyan”) is used to create a button on the screen.
  • self.nameofperson = nameofperson is used to enter their own name.
  • self.birthdate = birthdate is used to enter their own date of birth.
  • today = datetime.date.today() is used to enter the today date.
  • age = today.year-self.birthdate.year is used to enter the birthday date.
def getinput():
    nameofperson=nameofpersonEntry.get()
    dog = Person(nameofperson,datetime.date(int(yearentry.get()),int(monthentry.get()),int(dateentry.get())))
    
    textArea = tk.Text(master=wd,height=10,width=25)
    textArea.grid(column=1,row=6)
    answer = " Heyya {dog}!!. You are {age} years old!!! ".format(dog=nameofperson, age=dog.age())
    textArea.insert(tk.END,answer)
button=tk.Button(wd,text="Calculate Age Of Person",command=getinput,bg="cyan")
button.grid(column=1,row=5)
class Person:
    def __init__(self,nameofperson,birthdate):
        self.nameofperson = nameofperson
        self.birthdate = birthdate
    def age(self):
        today = datetime.date.today()
        age = today.year-self.birthdate.year
        return age

Read: Python Tkinter Color Game

Block of code:

In this Python Tkinter Age Calculator block of code, we will place the image above all the labels which look attractive on the screen.

  • image=Image.open(‘calculator.jpg’) is used to place the image on the screen.
  • photo=ImageTk.PhotoImage(image) is used to set the image on the screen.
  • labelimage=tk.Label(image=photo) is used to give the label as an image.
  • labelimage.grid(column=1,row=0) is used to create the image grid.
image=Image.open('calculator.jpg')
image.thumbnail((200,500),Image.ANTIALIAS)
photo=ImageTk.PhotoImage(image)
labelimage=tk.Label(image=photo)
labelimage.grid(column=1,row=0)
wd.mainloop()

Check this code in Repository from Github and you can also fork this code.

Github User Name: PythonT-Point

Code:

from tkinter import *
import datetime
import tkinter as tk
from PIL import Image,ImageTk
wd=tk.Tk()
wd.geometry("400x400")
wd.title("Pythontpoint")
nameofperson = tk.Label(text = "Name")
nameofperson.grid(column=0,row=1)
year = tk.Label(text = "Year")
year.grid(column=0,row=2)
month = tk.Label(text = "Month")
month.grid(column=0,row=3)
date = tk.Label(text = "Day")
date.grid(column=0,row=4)
nameofpersonEntry = tk.Entry()
nameofpersonEntry.grid(column=1,row=1)
yearentry = tk.Entry()
yearentry.grid(column=1,row=2)
monthentry = tk.Entry()
monthentry.grid(column=1,row=3)
dateentry = tk.Entry()
dateentry.grid(column=1,row=4)
def getinput():
    nameofperson=nameofpersonEntry.get()
    dog = Person(nameofperson,datetime.date(int(yearentry.get()),int(monthentry.get()),int(dateentry.get())))
    
    textArea = tk.Text(master=wd,height=10,width=25)
    textArea.grid(column=1,row=6)
    answer = " Heyya {dog}!!. You are {age} years old!!! ".format(dog=nameofperson, age=dog.age())
    textArea.insert(tk.END,answer)
button=tk.Button(wd,text="Calculate Age Of Person",command=getinput,bg="cyan")
button.grid(column=1,row=5)
class Person:
    def __init__(self,nameofperson,birthdate):
        self.nameofperson = nameofperson
        self.birthdate = birthdate
    def age(self):
        today = datetime.date.today()
        age = today.year-self.birthdate.year
        return age
image=Image.open('calculator.jpg')
image.thumbnail((200,500),Image.ANTIALIAS)
photo=ImageTk.PhotoImage(image)
labelimage=tk.Label(image=photo)
labelimage.grid(column=1,row=0)
wd.mainloop()

Output:

After running the above code we get the following output in which we can see that the labels and grid are placed on the screen where the user can enter the input according to the label and the calculated can calculate accordingly.

Python Tkinter Age calculator
Python Tkinter Age calculator

After entering the input in the entry box click on the Calculate Age Of Person button and the output is shown in the text box grid.

Python Tkinter Age calculator Output
Python Tkinter Age calculator Output

So, in this tutorial, we discussed Python Tkinter Age Calculator and we have explained this with the help of the example that you can see above.

167 thoughts on “Python Tkinter Age Calculator”

  1. Hey very cool website!! Man .. Excellent .. Amazing .. I’ll bookmark your web site and take the feeds additionally?KI’m happy to find so many useful info here in the put up, we want work out more strategies in this regard, thanks for sharing. . . . . .

    Reply
  2. Hi there! Do you know if they make any plugins to help with SEO?

    I’m trying to get my website to rank for some targeted keywords but I’m not
    seeing very good gains. If you know of any please share.
    Many thanks! You can read similar text here:
    Eco wool

    Reply
  3. Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?

    Reply
  4. I seriously love your website.. Great colors & theme. Did you create this web site yourself? Please reply back as I’m looking to create my own blog and would like to learn where you got this from or what the theme is called. Thanks.

    Reply
  5. Employees group incentive packages – Whether you are celebrating a program launch, unwinding after a day of company conferences, or holding your organization’s annual summer season social gathering, an interesting night occasion could be a major benefit to your corporation.

    Reply
  6. Hi, I do believe this is an excellent website. I stumbledupon it 😉 I’m going to return once again since I saved as a favorite it. Money and freedom is the best way to change, may you be rich and continue to guide other people.

    Reply
  7. I’d like to thank you for the efforts you’ve put in penning this site. I really hope to check out the same high-grade content from you later on as well. In fact, your creative writing abilities has inspired me to get my very own website now 😉

    Reply
  8. Hi, I do believe this is a great website. I stumbledupon it 😉 I’m going to return once again since i have book-marked it. Money and freedom is the best way to change, may you be rich and continue to help other people.

    Reply
  9. I truly love your blog.. Great colors & theme. Did you create this web site yourself? Please reply back as I’m planning to create my own personal blog and would love to learn where you got this from or exactly what the theme is named. Cheers.

    Reply
  10. I blog quite often and I truly thank you for your information. This great article has really peaked my interest. I am going to book mark your blog and keep checking for new information about once per week. I opted in for your RSS feed as well.

    Reply
  11. Hi, I do think this is a great website. I stumbledupon it 😉 I may revisit once again since I book-marked it. Money and freedom is the best way to change, may you be rich and continue to help other people.

    Reply
  12. I blog often and I really appreciate your information. This great article has really peaked my interest. I’m going to bookmark your website and keep checking for new details about once per week. I subscribed to your RSS feed as well.

    Reply
  13. Hello, I do think your website might be having browser compatibility issues. When I look at your blog in Safari, it looks fine however, if opening in I.E., it’s got some overlapping issues. I merely wanted to provide you with a quick heads up! Other than that, excellent website!

    Reply
  14. When I initially commented I appear to have clicked on the -Notify me when new comments are added- checkbox and from now on every time a comment is added I receive 4 emails with the exact same comment. Perhaps there is a way you can remove me from that service? Cheers.

    Reply
  15. I must thank you for the efforts you’ve put in writing this website. I am hoping to view the same high-grade content from you in the future as well. In fact, your creative writing abilities has encouraged me to get my own, personal website now 😉

    Reply
  16. Right here is the perfect site for everyone who wants to understand this topic. You realize a whole lot its almost hard to argue with you (not that I really will need to…HaHa). You definitely put a brand new spin on a topic that has been written about for decades. Wonderful stuff, just great.

    Reply
  17. Oh my goodness! Amazing article dude! Thanks, However I am having difficulties with your RSS. I don’t understand why I cannot subscribe to it. Is there anybody getting similar RSS issues? Anyone that knows the solution will you kindly respond? Thanx!!

    Reply
  18. I must thank you for the efforts you’ve put in writing this site. I am hoping to check out the same high-grade blog posts by you later on as well. In truth, your creative writing abilities has encouraged me to get my own, personal site now 😉

    Reply
  19. I’m amazed, I have to admit. Rarely do I encounter a blog that’s both equally educative and amusing, and without a doubt, you have hit the nail on the head. The issue is an issue that too few people are speaking intelligently about. I am very happy that I found this in my hunt for something relating to this.

    Reply
  20. I truly love your site.. Excellent colors & theme. Did you build this site yourself? Please reply back as I’m planning to create my very own site and want to know where you got this from or just what the theme is called. Kudos.

    Reply
  21. I’m impressed, I have to admit. Seldom do I encounter a blog that’s both equally educative and interesting, and let me tell you, you’ve hit the nail on the head. The problem is an issue that not enough people are speaking intelligently about. I am very happy that I stumbled across this during my hunt for something regarding this.

    Reply
  22. You are so interesting! I don’t suppose I’ve read a single thing like that before. So great to find someone with some genuine thoughts on this issue. Seriously.. thank you for starting this up. This web site is something that is required on the web, someone with a bit of originality.

    Reply
  23. After going over a handful of the blog articles on your website, I honestly like your technique of writing a blog. I bookmarked it to my bookmark website list and will be checking back soon. Please visit my website too and tell me your opinion.

    Reply
  24. Hi there, I do believe your website could possibly be having web browser compatibility issues. When I take a look at your web site in Safari, it looks fine but when opening in IE, it’s got some overlapping issues. I just wanted to provide you with a quick heads up! Besides that, excellent blog!

    Reply
  25. Having read this I thought it was extremely enlightening. I appreciate you taking the time and effort to put this article together. I once again find myself personally spending way too much time both reading and posting comments. But so what, it was still worth it.

    Reply
  26. Hi there, I think your web site could possibly be having web browser compatibility issues. When I look at your blog in Safari, it looks fine however when opening in I.E., it’s got some overlapping issues. I just wanted to provide you with a quick heads up! Besides that, excellent website.

    Reply
  27. Hi there, I do think your blog may be having browser compatibility problems. Whenever I take a look at your blog in Safari, it looks fine however, if opening in IE, it’s got some overlapping issues. I just wanted to give you a quick heads up! Besides that, wonderful website!

    Reply
  28. Hi! I could have sworn I’ve been to this website before but after browsing through many of the articles I realized it’s new to me. Regardless, I’m certainly pleased I found it and I’ll be bookmarking it and checking back frequently.

    Reply
  29. Having read this I thought it was rather informative. I appreciate you finding the time and effort to put this content together. I once again find myself spending a significant amount of time both reading and leaving comments. But so what, it was still worth it!

    Reply
  30. This is a good tip especially to those fresh to the blogosphere. Short but very precise info… Many thanks for sharing this one. A must read article.

    Reply
  31. May I just say what a comfort to uncover a person that actually knows what they are discussing on the net. You definitely realize how to bring an issue to light and make it important. A lot more people really need to check this out and understand this side of your story. I was surprised you are not more popular given that you most certainly have the gift.

    Reply
  32. I must thank you for the efforts you have put in writing this blog. I really hope to check out the same high-grade blog posts from you in the future as well. In fact, your creative writing abilities has encouraged me to get my very own site now 😉

    Reply
  33. May I simply just say what a comfort to discover a person that truly knows what they are discussing on the internet. You actually understand how to bring an issue to light and make it important. More people have to look at this and understand this side of the story. It’s surprising you are not more popular because you definitely possess the gift.

    Reply
  34. Hello there! I could have sworn I’ve been to this blog before but after browsing through a few of the articles I realized it’s new to me. Nonetheless, I’m definitely delighted I discovered it and I’ll be bookmarking it and checking back often!

    Reply
  35. Hi there, I do believe your site could possibly be having browser compatibility problems. When I look at your site in Safari, it looks fine but when opening in Internet Explorer, it has some overlapping issues. I simply wanted to provide you with a quick heads up! Other than that, great blog.

    Reply
  36. Right here is the perfect web site for anyone who hopes to understand this topic. You know so much its almost tough to argue with you (not that I actually would want to…HaHa). You definitely put a new spin on a topic that has been discussed for many years. Excellent stuff, just wonderful.

    Reply
  37. I blog quite often and I really appreciate your information. This great article has really peaked my interest. I will bookmark your blog and keep checking for new details about once per week. I opted in for your RSS feed as well.

    Reply
  38. Aw, this was a very good post. Taking the time and actual effort to make a great article… but what can I say… I put things off a whole lot and never manage to get nearly anything done.

    Reply
  39. I’m amazed, I must say. Rarely do I encounter a blog that’s equally educative and amusing, and let me tell you, you’ve hit the nail on the head. The problem is an issue that too few folks are speaking intelligently about. I’m very happy that I came across this during my search for something regarding this.

    Reply
  40. Good post. I learn something totally new and challenging on sites I stumbleupon on a daily basis. It will always be interesting to read articles from other authors and practice something from their websites.

    Reply
  41. The very next time I read a blog, Hopefully it doesn’t disappoint me as much as this one. I mean, I know it was my choice to read through, but I genuinely thought you would probably have something useful to say. All I hear is a bunch of whining about something you can fix if you were not too busy looking for attention.

    Reply
  42. Howdy! This blog post could not be written any better! Looking through this article reminds me of my previous roommate! He constantly kept preaching about this. I will send this article to him. Fairly certain he’ll have a very good read. Thank you for sharing!

    Reply
  43. I blog frequently and I genuinely appreciate your information. This article has really peaked my interest. I’m going to book mark your website and keep checking for new information about once a week. I subscribed to your RSS feed as well.

    Reply
  44. Hi, I do think this is a great blog. I stumbledupon it 😉 I’m going to return once again since I bookmarked it. Money and freedom is the best way to change, may you be rich and continue to guide other people.

    Reply
  45. A fascinating discussion is definitely worth comment. There’s no doubt that that you ought to write more about this subject, it may not be a taboo matter but generally people don’t discuss such issues. To the next! Cheers.

    Reply
  46. I blog quite often and I genuinely thank you for your information. The article has truly peaked my interest. I’m going to book mark your blog and keep checking for new information about once a week. I subscribed to your RSS feed too.

    Reply

Leave a Comment