Removing 'Week Number' column in Calendar Widget in Python
The documentation is poor, you have to dig in the source code.
The weeks number column corresponds to a list of wlabel
(instance of ttk.Label()
) called _week_nbs
. So you can loop over them and destroy them one after one:
for i in range(6): cal._week_nbs[i].destroy()
Full program:
try: import tkinter as tk from tkinter import ttkexcept ImportError: import Tkinter as tk import ttkfrom tkcalendar import Calendar, DateEntrydef example1(): def print_sel(): print(cal.selection_get()) top = tk.Toplevel(root) cal = Calendar(top, font="Arial 14", selectmode='day', cursor="hand1", year=2018, month=2, day=5) cal.pack(fill="both", expand=True) for i in range(6): cal._week_nbs[i].destroy() ttk.Button(top, text="ok", command=print_sel).pack()def example2(): top = tk.Toplevel(root) ttk.Label(top, text='Choose date').pack(padx=10, pady=10) cal = DateEntry(top, width=12, background='darkblue', foreground='white', borderwidth=2) cal.pack(padx=10, pady=10)root = tk.Tk()s = ttk.Style(root)s.theme_use('clam')ttk.Button(root, text='Calendar', command=example1).pack(padx=10, pady=10)ttk.Button(root, text='DateEntry', command=example2).pack(padx=10, pady=10)root.mainloop()
Demo:
The following seems to work to turn the weeknumbers off:
self.de = DateEntry(self.frame, width=12, background='darkblue', foreground='white',showweeknumbers=False,firstweekday='sunday')# To see other parameters that you can changeprint("DE keys=",self.de.keys())
Unfortunately, it doesn't come as an option. In the __init__
method of tkcalendar
the week numbers are always added, no matter what the options are:
... self._week_nbs = [] self._calendar = [] for i in range(1, 7): self._cal_frame.rowconfigure(i, weight=1) wlabel = ttk.Label(self._cal_frame, style='headers.%s.TLabel' % self._style_prefixe, font=self._font, padding=2, anchor="e", width=2) self._week_nbs.append(wlabel) wlabel.grid(row=i, column=0, sticky="esnw", padx=(0, 1)) self._calendar.append([]) for j in range(1, 8): label = ttk.Label(self._cal_frame, style='normal.%s.TLabel' % self._style_prefixe, font=self._font, anchor="center") self._calendar[-1].append(label) label.grid(row=i, column=j, padx=(0, 1), pady=(0, 1), sticky="nsew") if selectmode is "day": label.bind("<1>", self._on_click)
You may want to try other widgets as suggested here, it seems like ttkcalendar
wouldn't have week numbers.