python - 如何在 tkcalendar 中使用空白日期初始化日历?
问题描述
我正在尝试创建一个日期选择器。我在网上找到了一个适合我的代码。但是,使用此代码,程序在启动时默认显示今天的日期,如下所示:
有没有办法像这样将默认日期设置为空白?
我一直在寻找答案,但没有运气。
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()
解决方案
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")
推荐阅读
- c# - 在控制台窗口中创建单独的颜色
- javascript - 通过 javascript 和 vbscript 创建新的 Outlook 邮件项目
- c# - 在 ComboBox 中我的项目左侧添加一个彩色框
- postgresql - Docker 无法识别 Postgresql 数据目录
- unity3d - 在 Unity 中锁定子网格的尺寸比例
- python - 如何从数据框中的范围内制作列表?
- html - 我无法让我的徽标出现在导航栏上
- google-apps-script - 在谷歌表格中自动填充日期
- html - 是否可以在父标签中替换子元素标签?
- java - base64 编码字符串中的“分块”