pythontkintertkcalendar

How to initialise the calendar with blank date in tkcalendar?


I'm trying to create a date picker. I found a code online that works for me. However, with this code, the program shows today's date as default when it starts like this:

enter image description here

Is there a way to set the default date to blank like this?

enter image description here

I have been looking for an answer but no luck.

import tkinter as tk

from tkinter import ttk

from tkcalendar import DateEntry

from datetime import date

root = tk.Tk()

style = ttk.Style(root)

style.theme_use('clam')


class MyDateEntry(DateEntry):

    def __init__(self, master=None, **kw):

        DateEntry.__init__(self, master=None, **kw)

        self._top_cal.configure(bg='black', bd=1)


de = MyDateEntry(root,selectbackground='gray80',
                 selectforeground='black',
                 normalbackground='white',
                 normalforeground='black',
                 background='gray90',
                 foreground='black',
                 bordercolor='gray90',
                 othermonthforeground='gray50',
                 othermonthbackground='white',
                 othermonthweforeground='gray50',
                 othermonthwebackground='white',
                 weekendbackground='white',
                 weekendforeground='black',
                 headersbackground='white',
                 headersforeground='gray70')

de.pack()

root.mainloop()

Solution

  • DateEntry is inherited from Entry widget. So you can delete the content just like a normal Entry widget:

    class MyDateEntry(DateEntry):
    
        def __init__(self, master=None, **kw):
    
            DateEntry.__init__(self, master=None, **kw)
    
            self._top_cal.configure(bg='black', bd=1)
    
            self.delete(0, "end")