Jan-31-2024, 07:15 PM
(This post was last modified: Jan-31-2024, 07:15 PM by deanhystad.)
Use the tkcalendar module.
To answer your question:
I would make a generator using ideas mentioned in rob101's post.
import tkinter as tk from tkcalendar import DateEntry root = tk.Tk() date_entry = DateEntry(root) date_entry.pack(padx=10, pady=10) root.mainloop()This is not a standard library. You'll need to install the package, but the calendar layout is sooooo much better than a list of dates.
To answer your question:
I would make a generator using ideas mentioned in rob101's post.
from datetime import datetime, timedelta def dateiter(days=1, format="%a %d %B %Y", start=0): """Return days number of datestrings. Default starting date is today. You can specify a relative date using an integer for start (-1 is yesterday), or you can pass a datetime object. """ if isinstance(start, int): start = datetime.now() + timedelta(days=start) for x in range(days): yield (start + timedelta(days=x)).strftime(format) print(*dateiter(5), sep=", ") print(*dateiter(5, start=-2), sep=", ") print(*dateiter(5, start=-2, format="%b %d"), sep=", ")
Output:Wed 31 January 2024, Thu 01 February 2024, Fri 02 February 2024, Sat 03 February 2024, Sun 04 February 2024
Mon 29 January 2024, Tue 30 January 2024, Wed 31 January 2024, Thu 01 February 2024, Fri 02 February 2024
Jan 29, Jan 30, Jan 31, Feb 01, Feb 02