Date Handling

tks.dates provides 4 classes to obtain a date from a user.

DateVar
A Tk variable which holds a date.
DateEntry
Displays entry boxes for year, month and day as well as a button to display a date selection dialog.
DateDialog
Displays a dialog window allowing the user to select a date.
DateSelector
A widget which contains the date selection machinery.
class tks.dates.DateVar(master=None, value=None, name=None)

A Tkinter variable which holds a datetime.date

class tks.dates.DateEntry(master, variable=None, locale='en', fonts=None)

A date entry widget

Creates a frame which contains entry boxes for Year, Month and Day and a button to display a date selection dialog.

Dates will always consist of a 4 digit year and 2 digit months and days only the order and separator are determined by the locale parameter

Parameters:
  • master (ttk.Frame) – The master frame
  • variable (tks.dates.DateVar) – The variable which hold the date to display in the entry boxes.
  • locale (str or babel.Locale) – Determines the order of the widgets in the entry. Either a locale name e.g. ‘en’ or a babel Locale instance. If babel is not installed ISO 8601 format will be used.
  • fonts (DefaultFonts) – Fonts to use.
value

The date represented by the entry.

class tks.dates.DateDialog(master, title, start_date=None, locale='en', target_type='circle', fonts=None, colors=None)

Display a dialog to obtain a date from the user

Parameters:
  • master (ttk.Frame) – The master frame
  • title (str) – Dialog title
  • start_date (datetime.date or datetime.datetime) – The date to display in the entry boxes or None for today’s date
  • locale (str or babel.Locale) – Determines how today’s name is displayed Either a locale name e.g. ‘en’ or a babel Locale instance. If babel is not installed ISO 8601 format will be used.
  • target_type (TargetShape) – TargetShape.Square, TargetShape.Rectangle or TargetShape.Circle
  • fonts (DefaultFonts) – Font definitions to use
  • colors (DefaultColors) – Colors to use.
class tks.dates.DateSelector(master, start_date, locale='en', target_type='circle', fonts=None, colors=None)

A date selection widget

Parameters:
  • master (ttk.Frame) – The master frame
  • start_date (datetime.date or datetime.datetime) – The date to display in the entry boxes or None for today’s date
  • locale (str or babel.Locale) – Determines how today’s name is displayed Either a locale name e.g. ‘en’ or a babel Locale instance. If babel is not installed ISO 8601 format will be used.
  • target_type (TargetShape) – TargetShape.Square, TargetShape.Rectangle or TargetShape.Circle
  • fonts (tks.DefaultFonts) – Font definitions to use
  • colors (DefaultColors) – Colors to use.
class tks.dates.TargetShape

How to draw the target round a date