jeudi 26 novembre 2020

Python using tkcalendar with if-statements

Im trying to make if-statements with tkcalendar but dont know why it is not working.

from tkinter import *
from tkcalendar import *
import datetime

root = Tk()
root.title('Hi')
root.geometry('500x400')

cal = Calendar(root, date_pattern="d/m/y", year = 2020, month = 11, day = 1)
cal.pack(pady=20)

def grab_date():
    my_label.config(text = cal.get_date())
    d = cal.get_date()
    print(d)
    if datetime.datetime.strptime('01/11/2020', "%d/%m/%Y").strftime("%d/%m/%Y") 
    <=d<=datetime.datetime.strptime('01/1/2021', "%d/%m/%Y").strftime("%d/%m/%Y"):
        print('ok')

my_button = Button(root, text = 'Get date', command = grab_date)
my_button.pack()

my_label = Label(root, text = ' ')
my_label.pack(pady = 20)

root.mainloop()

It does not print 'ok' when I press the button between the dates. Does anyone know how I can fix this problem and how the if-statements are done when using tkcalendar? I want to then to add more conditions of when other dates are pressed print something else.

Aucun commentaire:

Enregistrer un commentaire