0
  • Problem is when I click the green color clear button number field text is not clear how to solve it?
from tkinter import *
from datetime import date

root = Tk()
root.title("AGE-CALCULATOR")
root.geometry("400x300")

now_date = str(date.today())

list_today = now_date.split("-")

def calculateAge(user_date,user_month,user_year):
    global today
    global a
    user_date = int(entry_date.get())
    user_month = int(entry_month.get())
    user_year = int(entry_year.get())

    enter_date = int(list_today[2])
    enter_month = int(list_today[1])
    enter_year = int(list_today[0])
    month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

    if (user_date>enter_date):
        enter_month = enter_month-1
        enter_date = enter_date+month[user_month-1]
    if (user_month>enter_month):
        enter_year = enter_year-1
        enter_month = enter_month+12

    date_result = str(enter_date-user_date)
    month_result = str(enter_month-user_month)
    year_result = str(enter_year-user_year)
    a = Label(root,text="YOU ARE \n"+year_result+" YEARS "+month_result+" MONTHS "+date_result+" DAYS "+ " OLD ",borderwidth=5)
    a.config(font=("Arial",16))
    a.grid(row=5,column=0,columnspan=3)

def clean(entry_date,entry_month,entry_year):
    entry_date.delete(0,END)
    entry_month.delete(0,END)
    entry_year.delete(0,END)

title_label = Label(root,text="AGE CALCULATOR",borderwidth=5)
title_label.config(font=("Arial",28))
title_label.grid(row=0,column=0,columnspan=3)

date_label = Label(root,text="DATE : ",borderwidth=4)
date_label.config(font=("Arial",15))
date_label.grid(row=1,column=0)

month_label = Label(root,text="MONTH : ",borderwidth=5)
month_label.config(font=("Arial",15))
month_label.grid(row=2,column=0)

year_label = Label(root,text="YEAR : ",borderwidth=9)
year_label.config(font=("Arial",15))
year_label.grid(row=3,column=0)

entry_date=Entry(root,width=20,borderwidth=4)
entry_month=Entry(root,width=20,borderwidth=4)
entry_year=Entry(root,width=20,borderwidth=4)

entry_date.grid(row=1,column=2)
entry_month.grid(row=2,column=2)
entry_year.grid(row=3,column=2)

user_date = entry_date.get()
user_month = entry_month.get()
user_year = entry_year.get()

final = Button(root,text="GIVE AGE !!",width=10,anchor=CENTER,command=lambda:calculateAge(user_date,user_month,user_year),bg="red",borderwidth=4)
final.grid(row=4,column=0)

clear_button = Button(root,text="CLEAR",width=10,command=clean(entry_date,entry_month,entry_year),bg="green",borderwidth=4)
clear_button.grid(row=4,column=2)

root.mainloop()

enter image description here

KompjoeFriek
  • 3,572
  • 1
  • 22
  • 35
Ali Arman
  • 1
  • 1
  • def clean(): entry_date.delete(0,END) entry_month.delete(0,END) entry_year.delete(0,END) clear_button = Button(root,text="CLEAR",width=10,command=clean, bg="green",borderwidth=4) – toyota Supra Jun 03 '22 at 20:52
  • 1
    @toyota Supra thanks for your reply. I try your code and my previous code I will commit and then apply your code but it's not working I hope you help me with this problem. [Screenshoot 01](https://ibb.co/HTWq3zn) [Screenshoot 02](https://ibb.co/BGbFwvx) – Ali Arman Jun 04 '22 at 13:29
  • In screehshoot 1 Do comment in. then replace this clear_button = Button(root,text="CLEAR",width=10,command=clean, bg="green",borderwidth=4) – toyota Supra Jun 04 '22 at 13:58
  • U had this def clean():. then comment in all 3. then replace this button = Button(root,text="CLEAR",width=10,command=clean, bg="green",borderwidth=4) – toyota Supra Jun 04 '22 at 14:07
  • In line #31 to line #38 are ok. Now replace line #74 with this clear_button = Button(root,text="CLEAR",width=10,command=clean, bg="green",borderwidth=4) – toyota Supra Jun 04 '22 at 14:22
  • 1
    @toyotaSupra still does not work clear button [Screenshot 3](https://ibb.co/f8NKK2y) [Screenshot 4](https://ibb.co/bPQ121c) [Screenshot 5](https://ibb.co/CvFzghT) – Ali Arman Jun 04 '22 at 15:39
  • screenshot4 is right. and screenshot 4 should be def clean() no parameter – toyota Supra Jun 04 '22 at 16:03

0 Answers0