- 原写法state='readonly’后发现无法选择日期
e2 = ttk.DateEntry(root,bootstyle='primary',dateformat='%Y-%m-%d', state='readonly',firstweekday=0,width=21)
- 重写一个CustomDateEntry类继承DateEntry控件
class CustomDateEntry(ttk.DateEntry):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.entry["state"] = "readonly"
def _on_date_ask(self):
self.entry["state"] = "normal"
super()._on_date_ask()
self.entry["state"] = "readonly"
- 新的写法,控件就支持readonly的同时选择日期
e2 = CustomDateEntry(root,bootstyle='primary',dateformat='%Y-%m-%d',firstweekday=0,width=21)