Python Forum
Date entry in box format issue
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Date entry in box format issue
#3
(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:
#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)
self.birthday.set('')
self.birthday=DateEntry(self, years=(1935, 2020))
self.birthday.place(relx=0.22, rely=0.16, height=25, width=100)
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()
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'
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.
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.
Reply


Messages In This Thread
Date entry in box format issue - by PeroPuri - Apr-18-2020, 08:03 PM
RE: Date entry in box format issue - by joe_momma - Apr-18-2020, 09:56 PM
RE: Date entry in box format issue - by PeroPuri - Apr-19-2020, 11:26 AM
RE: Date entry in box format issue - by joe_momma - Apr-19-2020, 04:10 PM
RE: Date entry in box format issue - by PeroPuri - Apr-20-2020, 10:24 PM
RE: Date entry in box format issue - by joe_momma - Apr-21-2020, 02:26 AM
RE: Date entry in box format issue - by PeroPuri - Apr-25-2020, 11:03 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Entry Widget issue PA3040 16 7,102 Jan-20-2021, 02:21 PM
Last Post: pitterbrayn
  Transfer Toplevel window entry to root window entry with TKinter HBH 0 4,528 Jan-23-2020, 09:00 PM
Last Post: HBH
  [Tkinter] how to get the entry information using Entry.get() ? SamyPyth 2 3,555 Mar-18-2019, 05:36 PM
Last Post: woooee

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020