Jun-29-2020, 07:25 PM
Hi!
I'm having a little bit of difficulty with a couple of things with my script:
When I'm writing in excel using this code:
I get something like this:
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:
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!
I'm having a little bit of difficulty with a couple of things with my script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
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() |
1 2 3 |
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 .birthday |
1 |
( '1' , 'January' , '2000' ) |
1 2 3 4 |
today_year = datetime.now().strftime( '%Y' ) age = int (today_year) - int ( self .cb_year.get()) print (age) |
I really can't solve this by myself so thank you all for your help!