May 2018
Beginner to intermediate
452 pages
11h 26m
English
Let's try creating a validating version of our Date field. We'll make a DateEntry widget that prevents most erroneous keystrokes, then checks for date validity on focusout. If the date is invalid, we'll mark the field in some way and display an error. Let's perform the following steps to do the same:
from datetime import datetime
class DateEntry(ttk.Entry):
"""An Entry for ISO-style dates (Year-month-day)"""
def __init__(self, parent, *args, **kwargs):
super().__init__(parent, *args, **kwargs)
self.config(
validate='all',
validatecommand=( self.register(self._validate), '%S', '%i', '%V', '%d' ), invalidcommand=(self.register(self._on_invalid), ...Read now
Unlock full access