Apr-19-2020, 11:26 AM
(Apr-18-2020, 09:56 PM)joe_momma Wrote: have you seen the tkcalendar widget? found hereThe benefit is it uses the calendar so you get leap years, super easy to use:I did saw the calendar script which is really beautiful, but I'm afraid it might need a lot of time and increment the chance of error input if used for birthday.
#from my interactive prompt. >>> from tkcalendar import Calendar, DateEntry >>> from tkinter import Tk >>> root= Tk() >>> date_entry= DateEntry(root) >>> date_entry.pack() >>> now= date_entry.get() >>> now '4/19/20' >>> mo_dy_yr= now.split('/') >>> mo= now[0] >>> mo '4' >>> dy= mo_dy_yr[1] >>> dy '19' >>> yr= mo_dy_yr[2] >>> yr '20'but if you're going to create a new one-
Quote:self.birthday = StringVar(self)first to create a string var and set it none then you over right the namespace and make it a dateentry widget. if you want the information you need .get()
self.birthday.set('')
self.birthday=DateEntry(self, years=(1935, 2020))
self.birthday.place(relx=0.22, rely=0.16, height=25, width=100)
at the bottom of your script I included a test:
if __name__ =='__main__': root= tk.Tk() d=DateEntry(root,years=('2000','2020')) d.pack() def get_entry(): txt=d.get() print(txt) btn= tk.Button(root,text='hello',command= get_entry) btn.pack()I did get an error when I tried to enter 1 in the year:
Quote:File "/home/pi/misc/yk_homeade_datepicker.py", line 46, in _validate
if v1 > 1 and len(value) < l:
TypeError: '>' not supported between instances of 'str' and 'int'
For what I've understand the script I'm trying to use gives back a dict and I don't know how to access it since it usually gives me back the "TypeError: get() takes 1 positional argument but 2 were given" error and I don't know why.