datefield(n)

πŸ“¦
version 0.7 Β· 3 versions
, in alpine 3.24

πŸ’… 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:

  1. the English form MM/DD/YYYY, using -format "%m/%d/%Y" β€” and this one is the default, bestie ✨
  2. the German form DD.MM.YYYY, using -format "%d.%m.%Y"
  3. 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 (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