0

How to check that an operator correctly enters a date?

I'm blocking on how to give a true value if a correct date Thank you in advance for your help

from tkinter import *
from tkinter.messagebox import * # boîte de dialogue

def Verification():
    if date_saisie.get() == 'python27':

        showinfo('Résultat','good date  by !')
        Mafenetre.destroy()
    else:
        showwarning('incorrect date. Please start over !')
        date_saisie.set('')

Mafenetre = Tk()
Mafenetre.title('Frame widget')
Mafenetre['bg']='bisque' # couleur de fond


Frame2 = Frame(Mafenetre,borderwidth=2,relief=GROOVE)
Frame2.pack(side=LEFT,padx=10,pady=10)

Label(Frame2,text="saisir une date \nEX:01/01/2020").pack(padx=10,pady=5)
date_saisie= StringVar()
date_saisie.set("01/01/2020")
Champ = Entry(Frame2, textvariable= date_saisie, bg ='bisque', fg='maroon')
Champ.focus_set()
Champ.pack(side = LEFT, padx = 10, pady = 5)
Bouton = Button(Mafenetre, text ='Valider', command = Verification)
Bouton.pack(side = LEFT, padx = 10, pady = 10)

Mafenetre.mainloop()
3

1 Answer 1

1

seriously, a simple google search can answer this you need to import datetime from datetime import datetime assume user_input is the one you got from tkinter

try:
    datetime.strptime(user_input, '%m/%d/%Y')
    print('The date {} is valid.'.format(user_input))
except ValueError:
    print('The date {} is invalid'.format(user_input))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.