Your code is grabbing the values of the Combobox's immediately after creating them.
You need to have a GUI selection made first and then possibly a button to click to submit the relevant Combobox selections.
The event from clicking the button would then read the current Combobox values.
I think I see now that you want the year calculated when any combobox value changes
You need to have a GUI selection made first and then possibly a button to click to submit the relevant Combobox selections.
The event from clicking the button would then read the current Combobox values.
I think I see now that you want the year calculated when any combobox value changes
from datetime import datetime from tkinter.ttk import * from tkinter import * from openpyxl import * class Application(Tk): def __init__(self, *args, **kwargs): Tk.__init__(self, *args, **kwargs) d29 = list(range(1, 30)) d30 = list(range(1, 31)) d31 = list(range(1, 32)) self.months = dict( January=d31, February=d29, March=d31, April=d30, May=d31, June=d30, July=d31, August=d31, September=d30, October=d31, November=d30, December=d31) self.lbl_birth = Label(self, text="Birthday:", font=('times', 14)) self.lbl_birth.grid(row=1, column=1) self.cb_day = Combobox(self, values=self.months["January"]) self.cb_day.bind('<<ComboboxSelected>>', self.update) self.cb_day.grid(row=1, column=2) self.cb_day.set("1") self.cb_month = Combobox(self, values=[*self.months]) self.cb_month.bind('<<ComboboxSelected>>', self.update) self.cb_month.grid(row=1, column=3) self.cb_month.set("January") self.cb_year = Combobox(self, values=list(range(1996, 2006))) self.cb_year.bind('<<ComboboxSelected>>', self.update) self.cb_year.grid(row=1, column=4) self.cb_year.set("2000") def update(self, event): day, month, year = self.cb_day.get(), self.cb_month.get(), self.cb_year.get() mydate = datetime.strptime(f'{day} {month} {year}', '%d %B %Y') today = datetime.now() years = today.year - mydate.year print(f'Years: {years}') if __name__ == "__main__": app = Application() app.title('My Birthday App') app.mainloop()