如何在tkcalendar中用空白日期初始化日历?

时间:2019-06-06 11:39:02

标签: python tkinter

我正在尝试创建日期选择器。我在网上找到了适合我的代码。但是,使用以下代码,该程序在启动时将如下所示作为默认日期:

enter image description here

有没有办法像这样将默认日期设置为空白?

enter image description here

我一直在寻找答案,但没有运气。

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()

1 个答案:

答案 0 :(得分:1)

DateEntry继承自Entry小部件。因此,您可以像普通的Entry小部件一样删除内容:

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")