MainWindow(3pm)
π Tk::MainWindow β the root widget of a widget tree, bestie π
okay so welcome to Tk::MainWindow, aka the main character of your entire Perl/Tk app. this is from the User Contributed Perl Documentation section of the manual (manual page name: MainWindow), and it's literally the root of everything. let's get into it π«Ά
β¨ SYNOPSIS β¨
use Tk;
my $mw = MainWindow->new( ... options ... );
my $this = $mw->ThisWidget -> pack ;
my $that = $mw->ThatWidget;
...
MainLoop;
πΈ DESCRIPTION πΈ
so basically, every Perl/Tk application that has windows attached to it creates one or more MainWindows, and those MainWindows act as the containers and the parents of all your other widgets. they're the mom friend of the widget tree fr fr.
Tk::MainWindow is a special kind of Toplevel widget β it's the root of a widget tree. and because it's the root, there's nobody above it, so $mw->Parent returns undef. yeah. it's giving orphan energy, but on purpose. π
the default title of a MainWindow is the basename of the script β actually, the Class name used for options lookup, i.e. the basename with inital caps (that typo is in the original, iykyk, we keep it π) β or 'Ptk' as the fallback value if that doesn't work out. and if you create more than one MainWindow, or several instances of the script are running at the same time, the string " #n" gets appended, where the number n is set to get a unique value. so you get the little numbered siblings, iconic. π₯
unlike standard Tcl/Tk's wish, perl/Tk allows you to create several MainWindows. when the last MainWindow is destroyed, the Tk eventloop exits β and btw the eventloop is entered when you call MainLoop. π¦
here's the tradeoff though, bestie: various resources (bindings, fonts, images, colors) are maintained or cached for each MainWindow, so each MainWindow consumes more resources than a Toplevel. π but multiple MainWindows can genuinely make sense when the user can destroy them independently. so it's a vibe, just a resource-hungry one. β
π METHODS π
you can apply all methods that a Toplevel widget accepts. no gatekeeping here, the whole Toplevel menu is yours. β¨
and the method $w->MainWindow, applied to any widget, will return the MainWindow to which the widget belongs β and yes, the MainWindow belongs to itself. self-love, we stan. π
π MISSING π
heads up: documentation is incomplete. here are some missing items that should be explained in more detail:
- the new mechanism for MainWindows is slightly different to other widgets. π
- there's no explanation about what resources are bound to a MainWindow (e.g.,
ClassInitdone per MainWindow). π§ - passing of command line options to override or augment arguments of the
newmethod (see Tk::CmdLine). π
π SEE ALSO π
Tk::ToplevelTk::CmdLine
okay that's the whole page, bestie, you ate it π this was the User Contributed Perl Documentation build for MainWindow, shipped as part of perl v5.40.1 and dated 2025-04-13. slay, go build something iconic. periodt. β¨ππ
π¦ 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