Jun-29-2020, 07:25 PM
Hi!
I'm having a little bit of difficulty with a couple of things with my script:
I really can't solve this by myself so thank you all for your help!
I'm having a little bit of difficulty with a couple of things with my script:
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.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.grid(row=1, column=4) self.cb_year.set("2000") items = [self.lbl_birth, self.cb_day, self.cb_month, self.cb_year] for t in items: self.grid_columnconfigure(t, weight=1) self.grid_rowconfigure(t, weight=1) def update(self, event): self.cb_day["values"] = self.months[self.cb_month.get()] self.cb_day.set("1") if __name__ == "__main__": app = Application() app.title('My Birthday App') app.mainloop()When I'm writing in excel using this code:
self.bday = self.cb_day.get(), self.cb_month.get(), self.cb_year.get() self.birthday = str(self.bday) sheet.cell(row=3, column=5).value = self.birthdayI get something like this:
('1', 'January', '2000')I've tried strftime and strptime to convert self.bday in a proper date format but without success (I always get some errors). Also I'm trying to calculate the age in years with this:
today_year = datetime.now().strftime('%Y') age = int(today_year) - int(self.cb_year.get()) print(age)It kinda works, but I always get back "20", as if self.cb_year.get() only gives me back the default year i put in set() and not the user input.
I really can't solve this by myself so thank you all for your help!