I did most of the job, but when I enter the variables that I want to calculate, it doesn't work. There is a problem with the function part and below. Can someone please help me? Thanks
from tkinter import *
win = Tk()
win.title("Age Generator")
win.geometry("600x300")
win.resizable(FALSE,FALSE)
etiket = Label(text="Welcome to the age generator.\nThis app, calculates your age with the year that you will choose",font="Cambria 12",fg="gray",anchor=CENTER)
etiket.place(relx=0.1,rely=0.1)
yaz = Label(text="Enter your age:",font="Cambria 10",bg="lightgray")
yaz.place(relx=0.2,rely=0.3)
age = Entry()
age.place(relx=0.4,rely=0.3)
yaz2 = Label(text="Ener the year:",font="Cambria 10",bg="lightgray")
yaz2.place(relx=0.2,rely=0.4)
year = Entry()
year.place(relx=0.4,rely=0.4)
def get_data():
cf1 = etiket.config(text= age.get(), font= ('Helvetica 13'))
cf2 = Label.config(text= year.get(), font= ('Helvetica 13'))
# label= Label(text="", font=('Helvetica 13'))
# label.pack()
result = Label(text=f"{year} yılında {cf2 - (2023-cf1)} yaşında olacaksınız!",font="Cambria Bold 10",bg="darkgray",fg="black",anchor=CENTER)
result.pack(side=BOTTOM)
button = Button(text="Calculate My Age",command=get_data,width=15,height=2)
button.place(relx=0.3,rely=0.5)
mainloop()
I was trying to do an application that tells you your age with the year that you choose. For example assume that I'm 20 and I'm asking which age I will be in 3786. The Machine answers it by the codes that I wrote.
But however, I always get TypeError.
The problem is that
cf1is the result of the call toconfig, not an integer. The same can be said forcf2. Because of this,f"{year} yılında {cf2 - (2023-cf1)won't work because you're trying to do math onLabels instead of numbers.You can fix this by separating the
getting of each value from theconfiguration ofcf1andcf2