TList(3pm)
π TList(3pm) β the Tk::TList glow-up π
okay bestie, gather round because we're doing the TList page today, and it is long β so this is part 1 of 3, and yes there's more coming, don't go anywhere π
This is from the User Contributed Perl Documentation, and the manual name is TList(3pm). Got it? Good. Let's go π¦
β¨ NAME β¨
Tk::TList β Create and manipulate Tix Tabular List widgets π
πΈ SYNOPSIS πΈ
$tlist = $parent->TList(?options?);
that's it. that's the whole vibe. one line and you're a list-making icon β¨
π SUPER-CLASS π
None.
literally no parent class. self-made. no nepotism. main character energy fr fr π
π¦ STANDARD OPTIONS π¦
these are the standard ones, the classics, the ones that come with the territory:
-background-borderwidth-class-cursor-foreground-font-height-highlightcolor-highlightthickness-relief-selectbackground-selectforeground-xscrollcommand-yscrollcommand-width
ngl if you want the deets on any of these, go read Tk::options. that's where the standard-option lore lives π
π WIDGET-SPECIFIC OPTIONS π
these are the ones that are hers. TList exclusives. the signature scent πΈ
-browsecmdβ Name:browsecmd, Class:BrowseCmd. tells TList which perl/Tk callback to run when the user browses through the entries in the widget. it's the lil "she's looking π" notification.-commandβ Name:command, Class:Command. the perl/Tk callback that fires when the user invokes a list entry. and by "normally" they mean: double-click it, or hit theReturnkey. that's the moment. that's the β¨invocationβ¨.-foregroundβ Name:foreground, Class:Foreground, Alias:-fg. sets the default foreground color for the list entries. the ink of your whole situation ποΈ-heightβ Name:height, Class:Height. how tall you want the window, measured in number of characters. yes, characters. it's giving vintage.-itemtypeβ Name:itemType, Class:ItemType. the default type of display item for this TList widget. so when you call the insert methods, items get created in this type β unless you pass-itemtypeyourself, in which case you're the boss π-orientβ Name:orient, Class:Orient. sets the order of tabularizing the list entries. two modes bestie:- set it to
"vertical"and the entries go in a column, top to bottom. if they don't all fit in one column, the leftovers spill into the next column, and so on. - set it to
"horizontal"and the entries go in a row, left to right. if they don't all fit in one row, the leftovers spill into the next row, and so on.
- set it to
-padxβ Name:padX, Class:Pad. the default horizontal padding for list entries. personal space, but sideways π«Ά-padxβ Name:padY, Class:Pad. the default vertical padding for list entries.
okay so, real talk β the switch listed forpadYis also-padxin this manual. we are reporting it exactly as it appears. no, we did not typo it. yes, we noticed. moving on π
-selectbackgroundβ Name:selectBackground, Class:SelectBackground. the background color for the selected list entries. the highlight reel π¬-selectborderwidthβ Name:selectBorderWidth, Class:BorderWidth. a non-negative value saying how wide the 3-D border around selected items should be. the value can take any of the forms thatTk_GetPixelsfinds acceptable. non-negative, bestie. we do not do negative borders here π-selectforegroundβ Name:selectForeground, Class:SelectForeground. the foreground color for the selected list entries. the chosen ones get the good text color π-selectmodeβ Name:selectMode, Class:SelectMode. picks one of several styles for manipulating the selection. the value can technically be arbitrary, but the default bindings expect it to be one ofsingle,browse,multiple, orextended. the default value issingle. (single, and unbothered π )-sizecmdβ Name:sizeCmd, Class:SizeCmd. a perl/Tk callback that gets called whenever the TList widget changes its size. this one is genuinely useful β it's how you build those "user scroll bars when needed" features π§-stateβ Name:state, Class:State. decides whether the TList command reacts to user actions at all."normal"β reacts to user actions in the normal way, everything works, slay."disabled"β it can only be scrolled. entries cannot be selected or activated. look, don't touch π«
-widthβ Name:width, Class:Width. how wide you want the window, in characters. width queen π
π DESCRIPTION π
The TList method makes a brand new window β the one given by the $widget argument β and turns it into a TList widget. you can pass the extra options we just went through on the command line, or stick them in the option database, to configure stuff like the cursor and the relief. customization era β¨
So what's the point of a TList? tabular data. displaying it. that's the whole gig. the list entries are honestly very similar to the entries in the Tk listbox widget β same family, different font. the main differences are:
- the TList widget can display its list entries in a two dimensional format, and
- you can use graphical images as well as multiple colors and fonts for the list entries.
so likeβ¦ listbox but she went to art school π¨
Every list entry is identified by an index, which can come in these forms:
index forms π
numberβ an integer showing the position of the entry in the list.0means the first position,1means the second position, and so on. zero-indexed bestie, we know πendβ indicates the end of the listbox. careful though: for some commands this means just after the last entry, and for other commands it means the last entry. context is everything.@x,yβ indicates the element that covers the point in the listbox window specified byxandy(in pixel coordinates). and if no element covers that point? then the closest element to that point gets used. it's giving "nearest neighbor" but make it cute.
π§ DISPLAY ITEMS π§
Every list entry in a TList widget is associated with a display item. that display item is what decides which visual information gets shown for that list entry. for the full roster of display items, go see Tk::DItem π
And when a list entry gets created by the insert command, the type of its display item is determined by the -itemtype option you pass to those commands. if you omit the -itemtype, then by default the type specified by this TList widget's own -itemtype option is used. so it always has a fallback, she's prepared π
β¨ WIDGET METHODS β¨
okay so the TList method is what actually births a widget object for you π. That's the whole origin story.
Once you've got one, it plays nice with the configure and cget methods from Tk::options β those two are how you peek at and mess with all the options we listed above. Your widget also inherits every single method that the generic Tk::Widget class hands out, so you're not starting from zero, bestie π«Ά.
And here's the extra menu β these are the methods that are specifically for TList widgets:
$tlist->anchorSet(index)β locks the anchor onto the list entry thatindexpoints at. The anchor is literally just the end of the selection that stays put while you're dragging a selection out with the mouse. One end moves, one end is the anchor. That's the vibe π$tlist->anchorClearβ yeets the anchor (if there even is one) out of thisTListwidget. Important, bestie: this only strips the surrounding highlights off the anchor entry. It does not touch whether that entry is selected. Two totally different things, don't get it twisted π$tlist->delete(from, ?to?)β deletes one or more list entries between the two entries given by the indicesfromandto. If you don't passto, it just deletes the single entry named byfrom. bye felicia π$tlist->dragsiteSet(index)β sets the dragsite to the list entry identified byindex. The dragsite is what marks the source of a drag-and-drop action. ngl though: drag-and-drop functionality has not been implemented in Tix yet. So it's giving very much "coming soon" energy π$tlist->dragsiteClearβ removes the dragsite, if any, from thisTListwidget. Again, this only removes the surrounding highlights of the dragsite entry and does not affect its selection status. Same rule as the anchor, fr fr.$tlist->dropsiteSet(index)β sets the dropsite to the list entry identified byindex. The dropsite marks the target of a drag-and-drop action. And yeahβ¦ same sad story: drag-and-drop functionality has not been implemented in Tix yet π«$tlist->dropsiteClearβ removes the dropsite, if any, from thisTListwidget. Yep, only the surrounding highlights go; selection status stays exactly where it was. periodt.$tlist->entrycget(index, option)β hands you back the current value of the configuration option named byoption, for the entry identified byindex.optioncan be any of the values that theinsertmethod accepts, so go wild β¨$tlist->entryconfigure(index, ?option?, ?value, option, value, ...?)β the query-or-modify queen for the config options of the list entry identified byindexπ- No
optionat all? You get a list describing every available option forindexβ seeTk_ConfigureInfofor how that list is formatted. optiongiven but novalue? You get a list describing just that one named option, and it'll be identical to the matching sublist of the big "no option" return.- One or more
option-valuepairs? Then it modifies the given option(s) to have the given value(s), and the method returns an empty string. optioncan be any of the values theinsertmethod accepts. And here's the tea: the exact set of options depends on the value of the-itemtypeoption that was passed to theinsertmethod back when this list entry was created. So it's not one-size-fits-all π¦
- No
$tlist->insert(index, ?option, value, ...?)β creates a brand new list entry at the position indicated byindex. These are the configuration options you can feed it:-itemtype => typeβ says what type of display item gets displayed for this new list entry.typehas to be a valid display item type. Currently the available display item types areimage,imagetext,text, and$widget. Skip this option and it just defaults to whatever type thisTListwidget's own-itemtypeoption says π«-state => stateβ says whether this entry can be selected or invoked by the user. Must be eithernormalordisabled. That's the whole menu, no substitutions.-data => dataβ arbitrary data to be associated with the entry (a perl scalar value). It's your lil secret pocket π
The insert method also accepts additional configuration options, and those are for configuring the display item that's tied to this list entry. Which set of extra options you get depends on the type of display item given by the -itemtype option. Please see Tk::DItem for the list of configuration options for each of the display item types β that's where the receipts live π§
$tlist->info(option, arg, ...)β queries info about theTListwidget.optioncan be one of these:$tlist->info(anchor, index)β returns the index of the current anchor, if there is one, of theTListwidget. If the anchor isn't set, you get the empty string back. no anchor, no answer π$tlist->info(dragsite, index)β returns the index of the current dragsite, if any, of theTListwidget. If the dragsite isn't set, empty string.$tlist->info(dropsite, index)β returns the index of the current dropsite, if any, of theTListwidget. If the dropsite isn't set, empty string.$tlist->info(selection)β returns a list of the selected elements in theTListwidget. If nothing is selected, you get an empty string. #nobodyselected π
$tlist->nearest(x, y)β you hand it an(x,y)coordinate that lives inside theTListwindow, and it hands you back the index of theTListelement nearest to that coordinate. It's a proximity detector, bestie π$tlist->see(index)β adjusts the view in theTListso that the entry given byindexis visible. If that entry is already visible then the command does absolutely nothing; otherwiseTListscrolls to bring the element into view at the edge it's nearest to. It's not extra, it's just helpful π$tlist->selection(option, arg, ...)β this is the command for adjusting the selection inside aTListwidget. It's got several forms depending onoption:$tlist->selectionClear(?from?, ?to?)β no extra arguments at all? It deselects all of the list entrie(s) in thisTListwidget. Onlyfromgiven? Only the list entry identified byfromgets deselected. Bothfromandtogiven? It deselects all the list entrie(s) betweenfromandto, inclusive, without touching the selection state of entries outside that range. precise, not messy β¨$tlist->selectionIncludes(index)β returns1if the list entry indicated byindexis currently selected; returns0otherwise. simple math, slay.$tlist->selectionSet(from, ?to?)β selects all the list entrie(s) betweenfromandto, inclusive, without affecting the selection state of entries outside that range. When onlyfromis given, only the list entry identified byfromis selected. π«Ά
$tlist->xview(args)β this one queries and changes the horizontal position of the information in the widget's window. It can take any of these forms:$tlist->xviewβ returns a list with two elements. Each element is a real fraction between0and1, and together they describe the horizontal span that's visible in the window. Like, if the first element is0.2and the second is0.6, then 20% of theTListentry is off-screen to the left, the middle 40% is visible in the window, and 40% of the entry is off-screen to the right. These are the exact same values that get passed to scrollbars via the-xscrollcommandoption π₯$tlist->xview(index)β adjusts the view in the window so the list entry identified byindexis aligned to the left edge of the window. snap it into place.$tlist->xviewMoveto(fraction)β adjusts the view so thatfractionof the total width of theTListis off-screen to the left.fractionmust be a fraction between0and1.$tlist->xviewScroll(number, what)β shifts the view left or right according tonumberandwhat.numbermust be an integer.whatmust be eitherunitsorpages, or an abbreviation of one of those. Ifwhatisunits, the view adjusts left or right bynumbercharacter units (that's the width of the0character) on the display; if it'spages, the view adjusts bynumberscreenfuls. Ifnumberis negative, characters farther to the left become visible; if it's positive, characters farther to the right become visible. directions matter, bestie β
$tlist->yview(?args?)β the vertical sibling π¦. This command queries and changes the vertical position of the entries in the widget's window. Forms:$tlist->yviewβ returns a list with two elements, both real fractions between0and1. The first element gives the position of the list element at the top of the window, relative to theTListas a whole (so0.5means it's halfway through theTList, for example). The second element gives the position of the list entry just after the last one in the window, relative to theTListas a whole. Same values that get passed to scrollbars via the-yscrollcommandoption π$tlist->yview(index)β adjusts the view so the list entry given byindexis displayed at the top of the window.$tlist->yviewMoveto(fraction)β adjusts the view so the list entry given byfractionappears at the top of the window.fractionis a fraction between0and1;0indicates the first entry in theTList,0.33indicates the entry one-third of the way through theTList, and so on. math but make it cute β¨$tlist->yviewScroll(number, what)β adjusts the view up or down according tonumberandwhat.numbermust be an integer.whatmust be eitherunitsorpages. Ifwhatisunits, the view adjusts up or down bynumberlines; if it'spages, the view adjusts bynumberscreenfuls. Ifnumberis negative then earlier entries become visible; if it's positive then later entries become visible. scroll responsibly π
π BINDINGS π
Okay bestie, here's the tea on how mouse stuff works in this widget, and it's all about what you set -selectmode to. Let's go number by number, no skips. π«Ά
[1]β If the-selectmodeis"browse", when the user drags the mouse pointer over the list entries, the entry under the pointer gets highlighted, and the-browsecmdprocedure gets called with one parameter: the index of the highlighted entry. Only one entry can be highlighted at a time. The-commandprocedure gets called when the user double-clicks on a list entry. π±οΈβ¨[2]β If the-selectmodeis"single", the entries only get highlighted by mouse<ButtonRelease-1>events. When a new list entry is highlighted, the-browsecmdprocedure gets called with one parameter indicating the highlighted list entry. The-commandprocedure gets called when the user double-clicks on a list entry. π[3]β If the-selectmodeis"multiple", when the user drags the mouse pointer over the list entries, all the entries under the pointer get highlighted. However, only a contiguous region of list entries can be selected. When the highlighted area changes, the-browsecmdprocedure gets called with an undefined parameter. It is the responsibility of the-browsecmdprocedure to find out the exact highlighted selection in the TList. The-commandprocedure gets called when the user double-clicks on a list entry. π₯[4]β If the-selectmodeis"extended", when the user drags the mouse pointer over the list entries, all the entries under the pointer get highlighted. The user can also make disjointed selections using<Control-ButtonPress-1>. When the highlighted area changes, the-browsecmdprocedure gets called with an undefined parameter. It is the responsibility of the-browsecmdprocedure to find out the exact highlighted selection in the TList. The-commandprocedure gets called when the user double-clicks on a list entry. π
π EXAMPLE π
This example demonstrates how to use an TList to store a list of numbers: π
use strict;
use Tk ();
use Tk::TList;
my $mw = Tk::MainWindow->new();
my $image = $mw->Getimage('folder');
my $tlist = $mw->TList(-orient => 'vertical');
for my $text ( qw/one two three four five six seven eight nine/ ) {
$tlist->insert('end',
-itemtype=>'imagetext', -image=>$image, -text=>$text);
}
$tlist->pack(-expand=>'yes', -fill=>'both');
Tk::MainLoop;
π¦ SEE ALSO π¦
Tk::optionsTk::WidgetTk::DItemTk::HListTk::TixGrid
β KEYWORDS β
Tix(n)Tabular ListboxDisplay Items
And that's the whole vibe, bestie π this page is from perl v5.40.1, dated 2025-04-13, and it's TList(3pm) β 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