datefield(n)
π datefield(n) β the Tk datefield widget, bestie π
okay so you're here because you need a widget that only wants dates, and honestly? it ate. this is datefield(n) from the tklib crew, and i'm gonna walk you through it like we're texting at 1am π«Ά
β¨ SYNOPSIS β¨
package require Tk
package require datefield ?0.3?
::datefield::datefield widgetpath ?options?
-format
that's the whole vibe check right there β load Tk, load datefield (version 0.3 if you're being specific π
), then make a widget with a widgetpath and some ?options?.
πΈ DESCRIPTION πΈ
the datefield package gives you the datefield widget β which is lowkey just an enhanced text entry widget made specifically for typing dates in. no cap. ποΈ
there are three valid formats for the dates you can enter:
- the English form
MM/DD/YYYY, using-format "%m/%d/%Y"β and this one is the default, bestie β¨ - the German form
DD.MM.YYYY, using-format "%d.%m.%Y" - the ISO form
YYYY-MM-DD, using-format "%Y-%m-%d"
and here's the tea π₯: the datefield widget is in fact just an entry widget with specialized bindings. which means every single command and option that works on an entry widget applies equally here. same energy, different wig. πββοΈ
π COMMANDS π
::datefield::datefield widgetpath ?options?β creates and configures a date field widget. that's it, that's the command, main character energy fr fr β¨
π OPTIONS π
-formatβ one of"%m/%d/%Y"(English, and the default if you just leave the option off entirely π),"%d.%m.%Y"(German), or"%Y-%m-%d"(ISO).
and for all the remaining/available options? go read the entry manual, bestie β they all apply here, every last one π
side note: the synopsis up top also lists -format on its own line, which is giving "the one option we care about" and honestly, mood.
π¦ EXAMPLE π¦
like, here's a whole working thing so you can copy-paste and feel something π
package require datefield
wm title . "Datefield example"
proc DayOfWeek {args} {
set now [clock scan $::myDate]
set ::myDate2 [clock format $now -format %A]
}
trace variable myDate w DayOfWeek
::datefield::datefield .df -textvariable myDate -format "%m/%d/%Y"
label .l1 -text "Enter a date:" -anchor e
label .l2 -text "That date is a:" -anchor e
label .l3 -textvariable myDate2 -relief sunken -width 12
grid .l1 .df -sticky ew
grid .l2 .l3 -sticky ew
focus .df
the way this works: you type a date, the trace fires DayOfWeek, clock scans your myDate, then clock formats it with %A to get the weekday name into myDate2. iconic. π₯
π BUGS, IDEAS, FEEDBACK π
ngl, this document and the package it describes will undoubtedly contain bugs and other problems β no software is safe from the curse π. please report them in the category datefield of the Tklib Trackers at http://core.tcl.tk/tklib/reportlist. and if you have ideas for enhancements to either the package and/or the documentation? also send those there. we love a feedback loop π«Ά
β SEE ALSO β
π KEYWORDS π
clock, date, dateentry, entry, widget
π§ CATEGORY π§
Widget
π COPYRIGHT π
Copyright (c) Keith Vetter <keith@ebook.gemstar.com>
Copyright (c) Thomas Wunderlich <tcl.tk@blindenfreizeiten.de>
that's the whole page, bestie β you're literally a datefield expert now π β¨
signing off from tklib version 0.3 (dated datefield(n)) β mwah, go build something cute π
π¦ where this page comes from
- alpine 3.24: tk-lib-doc 0.7-r0 Β· TCL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms