overview(3pm)
π NAME π
Tk::overview β a whole vibe check on an Object Oriented Tk8 extension for perl5, bestie πΈ
β¨ SYNOPSIS β¨
use Tk;
$main = MainWindow->new();
$widget = $main->Widget(...);
$widget->pack(...);
...
MainLoop;
π¦ DESCRIPTION π¦
okay so when the perl Tk extension was being written, the goals were literally two things: give you a complete interface to the latest production version of John Ousterhout's Tk, and serve it up with an Object Oriented interface to perl code. two goals. slay. π
π CONTENTS π
The package is composed of three loosely connected parts, and honestly? it's giving "three besties, one group chat":
π§ pTk - Converted Tk source
The pTk sub-directory is a copy of the C code of Tk8.x, modified to allow use by languages other than the original Tcl. (and you can read "pTk" as 'perl' Tk or 'portable' Tk, whichever one matches your sensibilities, no cap. both are valid. pick your main character era.) π«Ά
π Tk to Perl 'Glue'
The top level directory provides Tk.xs and tkGlue.c which provide the perl-callable interfaces to pTk. it's the glue, it holds everything together, iconic behavior honestly β¨
π Perl code for 'Widget' Classes
The Tk sub-directory contains the various perl modules that comprise the "Classes" that are visible to Tk applications.
The "major" widgets such as Tk::Text are actually in separate directories at the top level (e.g. Text/* for Tk::Text) and are dynamically loaded as needed on platforms which support perl5's DynaLoader. lazy-loaded icon behavior fr fr πΈ
π CLASS HIERARCHY π
β package Tk; - the 'base class'
All the "command names" documented in Tcl/Tk are made to look like perl sub's and reside in the Tk package. Their names are all lower case. Typically there are very few commands at this level which are called directly by applications.
π₯ package Tk::Widget; - the 'Widget class'
There are no actual objects of the Tk::Widget class; however all the various Tk window "widgets" inherit from it, and it in turn inherits all the core Tk functions from Tk. it's the ancestor, the blueprint, the lore π
Tk::Widget provides various functions and interfaces which are common to all Widgets.
A widget is represented to perl as a blessed reference to a hash. There are some members of the hash which are private to Tk and its tkGlue code. Keys starting with . and of the form /^_[A-Z][A-Za-z_]+_$/ (i.e. starting and ending in _ and with first char after _ being upper case) should be considered reserved to Tk.
π¨ bestie listen: those keys are Tk's, not yours. do not touch. hands off. reserved means reserved, periodt.
π Tk::Button, Tk::Entry, Tk::Text ...
There is one class for each of the "Tk" widget item types. Some of them like Tk::Frame do very little indeed, and really only exist so that they can be derived from or so that focus or menu traversal can discover the "kind" of window being processed. (Tk::Frame is the chill one who just shows up and holds the group together π«Ά)
Other classes, Tk::Text for example, provide a lot of methods used with Tk's "bind" to provide a rich keyboard/mouse interface to the widgets' data.
These widget classes also include conversions of the Tcl code for event bindings, keyboard focus traversal, menu bars, and menu keyboard traversal. All the Tcl functions have been converted, but the names have changed (systematically) and they have been split up between the various classes in what I hope is an appropriate manner. Name changes are normally: dropping initial tk_ as the Tk-ness is implicit in the Tk:: prefix, and similarly dropping say Menu from the name if it has been moved the Tk::Menu class. Thus proc tkMenuNextEntry becomes sub NextEntry in the Tk::Menu package. glow-up via renaming, we love to see it π
π¦ Tk::Image
This does for Tk8.x's "images" what Tk::Widget does for widgets. Images are new to Tk8.x and the class structure is not mature either. it's still figuring itself out, and that's okay π±
There are three sub-classes Tk::Bitmap, Tk::Pixmap and Tk::Photo.
It is possible to create dynamic or auto-loaded image types inherited from Tk::Image for other image types or photo formats (e.g. support for TIFF format). β¨
πΈ Composite Widgets
A composite is some kind of 'frame' with subwidgets which give it useful behaviour. Tk::Dialog is an example of a composite widget classes built from the basic Tk ones. It is intended that user code should not need to be aware that a particular class is a composite, and create and configure such widgets in the same manner as any other kind. The configure mechanism and the methods of the class manipulate the subwidgets as required.
Composite widgets are implemented via Tk::Frame and multiple inheritance. The two 'frame' base classes Tk::Frame and Tk::Toplevel include the additional class Tk::Derived in their inheritance. Tk::Derived provides methods to allow additional configure options to be defined for a widget.
A Composite widget is typically defined as derived from Tk::Frame or Tk::Toplevel (e.g. Tk::Dialog).
and that's the whole tour, bestie π you now know the lore. go forth and MainLoop; responsibly.
this page is overview(3pm), from perl v5.40.1, dated 2025-04-13, part of the User Contributed Perl Documentation. mwah, thanks for reading, i'm obsessed with you πβ¨
π¦ where this page comes from
- debian trixie: perl-tk 1:804.036+dfsg1-5
- ubuntu questing: perl-tk 1:804.036+dfsg1-5
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms