|
16 | 16 | dates = [
|
17 | 17 | "2024-04-08", "2024-04-10", "2024-04-11", "2024-04-12",
|
18 | 18 | "2024-04-15", "2024-04-16", "2024-04-17", "2024-04-18", "2024-04-19",
|
19 |
| - "2024-04-22", |
| 19 | + "2024-04-22", |
| 20 | + |
20 | 21 | "2024-05-21", "2024-05-22", "2024-05-23", "2024-05-24",
|
21 | 22 | "2024-05-27", "2024-05-28", "2024-05-29", "2024-05-30", "2024-05-31",
|
| 23 | + |
22 | 24 | "2024-06-03", "2024-06-04", "2024-06-05", "2024-06-07",
|
23 | 25 | "2024-06-10", "2024-06-11", "2024-06-12", "2024-06-13", "2024-06-14",
|
24 | 26 | ]
|
|
53 | 55 | )
|
54 | 56 | date_entry.pack()
|
55 | 57 |
|
| 58 | +def show_allowed_dates(): |
| 59 | + for date in cal['allowed_dates']: # not `cal.allowed_dates` |
| 60 | + print('allowed:', date) |
| 61 | + |
| 62 | +button_show = tk.Button(root, text="Show Allowed Dates", command=show_allowed_dates) |
| 63 | +button_show.pack(fill='x') |
| 64 | + |
| 65 | +def add_allowed_date(date): |
| 66 | + dt_date = dt.date.fromisoformat(date) |
| 67 | + |
| 68 | + if dt_date not in cal['allowed_dates']: |
| 69 | + print('add allowed:', date) |
| 70 | + |
| 71 | + cal['allowed_dates'].append(dt_date) |
| 72 | + # other methods |
| 73 | + #cal['allowed_dates'] += [append(dt.date.fromisoformat(date)] |
| 74 | + #cal['allowed_dates'].extend( [append(dt.date.fromisoformat(date)] ) |
| 75 | + |
| 76 | + cal['allowed_dates'] = sorted(cal['allowed_dates']) |
| 77 | + |
| 78 | + # what if new date is not in `mindate`, `maxdate` ??? |
| 79 | + if cal['allowed_dates'][0] < cal['mindate']: |
| 80 | + cal['mindate'] = cal['allowed_dates'][0] |
| 81 | + |
| 82 | + if cal['allowed_dates'][-1] > cal['maxdate']: |
| 83 | + cal['maxdate'] = cal['allowed_dates'][-1] |
| 84 | + |
| 85 | + # redraw it |
| 86 | + cal._display_calendar() |
| 87 | + |
| 88 | +for date in ('2024-06-06', '2024-06-26', '2024-07-10'): |
| 89 | + button_add = tk.Button(root, text=f"Add Allowed Date: {date}", command=lambda x=date:add_allowed_date(x)) |
| 90 | + button_add.pack(fill='x') |
| 91 | + |
| 92 | +def remove_allowed_date(date): |
| 93 | + dt_date = dt.date.fromisoformat(date) |
| 94 | + |
| 95 | + if dt_date in cal['allowed_dates']: |
| 96 | + print('remove allowed:', date) |
| 97 | + |
| 98 | + cal['allowed_dates'].remove(dt_date) |
| 99 | + |
| 100 | + # what if removed date is `mindate` or `maxdate` ??? |
| 101 | + if cal['mindate'] < cal['allowed_dates'][0]: |
| 102 | + cal['mindate'] = cal['allowed_dates'][0] |
| 103 | + |
| 104 | + if cal['maxdate'] > cal['allowed_dates'][-1]: |
| 105 | + cal['maxdate'] = cal['allowed_dates'][-1] |
| 106 | + |
| 107 | + # redraw it |
| 108 | + cal._display_calendar() |
| 109 | + |
| 110 | +for date in ('2024-06-06', '2024-06-26', '2024-07-10'): |
| 111 | + button_remove = tk.Button(root, text=f"Remove Allowed Date: {date}", command=lambda x=date:remove_allowed_date(x)) |
| 112 | + button_remove.pack(fill='x') |
| 113 | + |
56 | 114 | root.mainloop()
|
0 commit comments