|
| 1 | +from _datetime import datetime |
| 2 | +import tkinter as tk |
| 3 | +from tkinter import ttk |
| 4 | +from _datetime import * |
| 5 | + |
| 6 | +win = tk.Tk() |
| 7 | +win.title('Age Calculate') |
| 8 | +win.geometry('310x400') |
| 9 | +# win.iconbitmap('pic.png') this is use extention ico then show pic |
| 10 | + |
| 11 | +############################################ Frame ############################################ |
| 12 | +pic = tk.PhotoImage(file=r"E:\Python Practice\Age_calculate\pic.png") |
| 13 | +win.tk.call('wm','iconphoto',win._w,pic) |
| 14 | + |
| 15 | + |
| 16 | +canvas=tk.Canvas(win,width=310,height=190) |
| 17 | +canvas.grid() |
| 18 | +image = tk.PhotoImage(file=r"E:\Python Practice\Age_calculate\pic.png") |
| 19 | +canvas.create_image(0,0,anchor='nw',image=image) |
| 20 | + |
| 21 | +frame = ttk.Frame(win) |
| 22 | +frame.place(x=40,y=220) |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | +############################################ Label on Frame ############################################ |
| 27 | + |
| 28 | +name = ttk.Label(frame,text = 'Name : ',font = ('',12,'bold')) |
| 29 | +name.grid(row=0,column=0,sticky = tk.W) |
| 30 | + |
| 31 | +year = ttk.Label(frame,text = 'Year : ',font = ('',12,'bold')) |
| 32 | +year.grid(row=1,column=0,sticky = tk.W) |
| 33 | + |
| 34 | +month = ttk.Label(frame,text = 'Month : ',font = ('',12,'bold')) |
| 35 | +month.grid(row=2,column=0,sticky = tk.W) |
| 36 | + |
| 37 | +date = ttk.Label(frame,text = 'Date : ',font = ('',12,'bold')) |
| 38 | +date.grid(row=3,column=0,sticky = tk.W) |
| 39 | + |
| 40 | +############################################ Entry Box ############################################ |
| 41 | +name_entry = ttk.Entry(frame,width=25) |
| 42 | +name_entry.grid(row=0,column=1) |
| 43 | +name_entry.focus() |
| 44 | + |
| 45 | +year_entry = ttk.Entry(frame,width=25) |
| 46 | +year_entry.grid(row=1,column=1,pady=5) |
| 47 | + |
| 48 | +month_entry = ttk.Entry(frame,width=25) |
| 49 | +month_entry.grid(row=2,column=1) |
| 50 | + |
| 51 | +date_entry = ttk.Entry(frame,width=25) |
| 52 | +date_entry.grid(row=3,column=1,pady=5) |
| 53 | + |
| 54 | + |
| 55 | +def age_cal(): |
| 56 | + name_entry.get() |
| 57 | + year_entry.get() |
| 58 | + month_entry.get() |
| 59 | + date_entry.get() |
| 60 | + cal = datetime.today()-(int(year_entry)) |
| 61 | + print(cal) |
| 62 | + |
| 63 | + |
| 64 | +btn = ttk.Button(frame,text='Age calculate',command=age_cal) |
| 65 | +btn.grid(row=4,column=1) |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | +win.mainloop() |
0 commit comments