I am looking to move the number of the days in each square from the middle to the top left. I have read through the documentation of tkcalendar, and i have not been able to find anything online. I have not been able to try anything since i still have yet to see any examples where this is done. Could someone help me with this if it is possible?
system = macOS Mojave 10.14.6
coding level = noob - beginner
Thank you for your help and time.
There is no option to change the position of the day numbers. Therefore, it is necessary to dig into the source code of the widget to do it. The days are just labels so it is possible get the desired position by setting their anchor
option to "nw"
. They are stored into a list of lists called ._calendar
(one list per week):
import tkinter as tk
from tkcalendar import Calendar
class MyCalendar(Calendar):
def __init__(self, master, **kw):
Calendar.__init__(self, master, **kw)
for row in self._calendar:
for label in row:
label['anchor'] = "nw"
# # uncomment this block to align left weekday names
# for label in self._week_days:
# label['anchor'] = "w"
root = tk.Tk()
cal = MyCalendar(root, showweeknumbers=False)
cal.pack(fill='both', expand=True)
root.geometry("400x300")
root.mainloop()