Tk::EntryCheck(3)

πŸ“¦
version 0.04 Β· 4 versions
, in epel 9

πŸ’– Tk::EntryCheck(3) β€” your Tk::Entry, but with boundaries and a glow-up πŸ’–

πŸ’– NAME πŸ’–

Tk::EntryCheck β€” an interface to Tk::Entry for controlling its maximum length and content in an easy way. That’s the whole vibe. Periodt. πŸ’…

✨ SYNOPSIS ✨

  use Tk;
  use Tk::EntryCheck;

  my $mw = MainWindow->new();

  my $entry = $mw->EntryCheck(

    # some standard Entry-Options which are forwarded to Tk::Entry
    -width => 20,

    # and now the new options
    -maxlength => 10,     # accepts 10 chars at maximum for content
    -pattern   => qr/\d/, # accepts only \d, nothing else
  )
  ->pack();

  MainLoop();

🌸 DESCRIPTION 🌸

Okay so this module is lowkey a little wrapper around Tk::Entry, and it adds an easy-to-use interface to -validate and -validatecommand for controlling the length and content of an entry widget. It’s giving β€œentry widget but make it behave.” ✨

It’s giving you these additional features:

  • -maxlenght β€” set a maximum length for this entry with this parameter. If it’s defined but is not a positive integer, it gives a warning by carp. If the content is added by changing a variable attached as -textvariable, it also gives a warning with carp and denies the change. πŸ›‘
  • -pattern β€” allow only certain characters inside this entry. You can submit it as a regular expression in the parameter -pattern, e.g.
  -pattern => qr/[A-Za-z0-9]/, # alphanumeric

  -pattern = qr/\d/,           # numbers only

  -pattern = qr/[A-Z ]/,       # capital characters and spaces

If the content is added by a variable attached to the widget as -textvariable, it also gives a warning with carp and denies the change.

⚠️ ATTENTION: this character class check is done for each character and enhanced internally by *, so don't try to use something like -pattern = qr(\d+)>, because that would result in \d+* and give an error. 😭
⚠️ ATTENTION: don't forget to specify an empty space if you need it... like, actually put the space in there, bestie.

If you want to overwrite the methods used for validation, you can do so by just setting the original entry options -validate and/or -validatecommand... 🫢

🧸 Dependencies 🧸

  • Perl-Version >= 5.005
  • Tk and Tk::Entry must be installed and running

🚫 EXPORT 🚫

Nothing. As there is no need for exports and as I hate namespace pollution, I removed the Exporter... no cap, we keep it clean. 🧼

πŸ‘€ SEE ALSO πŸ‘€

See Tk::Entry for the other options, especially the options -validate and -validatecommand β€” that’s where the rest of the lore lives. πŸ‘‘

See Tk::FilterEntry which is similar.

πŸ¦‹ Differences between Tk::EntryCheck and Tk::FilterEntry πŸ¦‹

  • FilterEntry doesn't deny adding invalid chars or strings which are too long
  • EntryCheck just checks each char if it in a characterclass, whereas FilterEntry checks the whole content with a regular expression, so it is more helpful when checking for special formats
  • FilterEntry (v0.02) gives a warning if the field is empty
  • FilterEntry gives nice textcolors if the content of the textfield is invalid; but that just works when the widget leaves the focus (V0.02)

See http://www.fabiani.net/ β€” My Homepage (in German)

See http://www.perl-community.de/ β€” German Perl Forum

πŸ’œ AUTHOR πŸ’œ

Martin Fabiani (aka Strat), martin@fabiani.net

Copyright (C) 2004 by Martin Fabiani

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.3 or, at your option, any later version of Perl 5 you may have available.


Okay that’s the whole page, bestie β€” source/version vibes: perl v5.32.1, dated 2024-09-24, and the manual is Tk::EntryCheck(3). Mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from