Aug-08-2023, 11:00 AM
Good day how do you make TkCalendar DatePicker start with an empty default value.
|
Empty default value for tkCalender
|
|
Aug-08-2023, 11:00 AM
Good day how do you make TkCalendar DatePicker start with an empty default value.
Aug-08-2023, 12:08 PM
I guess you want
Calendar().selection_clear().from tkinter import Tk, Button, StringVar
from datetime import date
from tkcalendar import Calendar
def calendar_selected(event):
selected_date = date.fromisoformat(selection.get())
print("Selected Date:", selected_date)
root = Tk()
root.title("Demo Calendar")
# setting selection to previous month
today = date.today()
if today.month == 1:
today = today.replace(year=today.year - 1, month=12)
else:
today = today.replace(month=today.month - 1)
# this here is used to set the selection of year, month and day
selection = StringVar(root, value=today.isoformat())
# date_pattern to iso8601
cal = Calendar(root, textvariable=selection, date_pattern="y-mm-dd")
# clear the selection of day. Month and year stays
cal.selection_clear()
# binding the virtual event to calendar_selected
cal.bind("<<CalendarSelected>>", calendar_selected)
cal.pack()
Button(root, text="Quit", command=root.destroy).pack()
root.mainloop()
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Aug-08-2023, 04:57 PM
(Aug-08-2023, 12:08 PM)DeaD_EyE Wrote: I guess you want Thank you so much it worked perfectly |
|
|
| Possibly Related Threads… | |||||
| Thread | Author | Replies | Views | Last Post | |
| unexplained issue with tkcalender module. | cybertooth | 8 | 15,830 |
Aug-12-2021, 11:00 PM Last Post: deanhystad |
|