container(n)
okay bestie, gather round π this is container(n) from the BLT Built-In Commands crew, and it's giving βlet a foreign window live inside your Tk app.β no cap, it's a whole vibe.
π NAME π
container β Widget to contain a foreign window. that's it, that's the job, and it does it iconically π«Ά
β¨ SYNOPSIS β¨
container pathName ?options?
π DESCRIPTION π
The container widget is your VIP section for windows: it lets you swallow another X11/Win32 toplevel or embed an X11 window from a foreign application straight into your Tk application. The foreign window gets reparented inside of the widget β yes, literally moved into it π
. After that, you can place and arrange the container just like any other Tk widget. iconic behavior.
πΈ INTRODUCTION πΈ
Notebooks are a popular graphical paradigm, and honestly? slay. They let you organize a whole bunch of windows inside a single widget. Picture this: your application displays several X-Y graphs at the same time. Typically you can't pack those graphs into the same frame because they're too large π. The other alternative is packing the graphs into several toplevel widgets so they can overlap on screen β but then all those different toplevel windows clutter the screen and are difficult to manage. not the vibe.
The container widget lets you organize your application by displaying each graph as a page in a folder of a notebook π₯. Only one page is visible at a time. When you click on a tab, the folder (graph) corresponding to that tab is displayed in the container widget. The container also lets you temporarily tear pages out of the notebook into a separate toplevel widget, and put them back in the container later. For example, you could compare two graphs side-by-side by tearing them out, and then replace them when you're finished. main character flexibility, fr fr.
A container may contain an unlimited number of folders. If there are too many tabs to view, you can arrange them as multiple tiers or scroll the tabs. The container uses the conventional Tk scrollbar syntax, so you can attach a scrollbar too. we love options π
π¦ EXAMPLE π¦
You create a container widget with the container command.
# Create a new container
container .c
A new Tcl command .c is also created. This command can be used to query and modify the container. For example, to change the default borderwidth, you use the new command and the container's configure operation.
# Change the default font.
.c configure -borderwidth 2
You can then add folders using the insert operation.
# Create a new folder "f1"
.c coinsert 0 "f1"
This inserts the new tab named "f1" into the container. The index 0 indicates location to insert the new tab. You can also use the index end to append a tab to the end of the container. By default, the text of the tab is the name of the tab. You can change this by configuring the -text option. (The example below uses -label β that's exactly how the page has it, so we're keeping it π
.)
# Change the label of "f1"
.ts tab configure "f1" -label "Tab #1"
The insert operation lets you add one or more folders at a time.
.ts insert end "f2" -label "Tab #2" "f3" "f4"
The tab on each folder contains a label. A label may display both an image and a text string. You can reconfigure the tab's attributes (foreground/background colors, font, rotation, etc) using the tab configure operation.
# Add an image to the label of "f1"
set image [image create photo -file stopsign.gif]
.ts tab configure "f1" -image $image
.ts tab configure "f2" -rotate 90
Each folder may contain an embedded widget to represent its contents. The widget to be embedded must be a child of the container widget. Using the -window option, you specify the name of widget to be embedded. But don't pack the widget, the container takes care of placing and arranging the widget for you π«Ά.
graph .ts.graph
.ts tab configure "f1" -window ".ts.graph" \
-fill both -padx 0.25i -pady 0.25i
The size of the folder is determined by the sizes of the Tk widgets embedded inside each folder. The folder will be as wide as the widest widget in any folder. The tallest determines the height. You can use the tab's -pagewidth and -pageheight options to override this.
Other options control how the widget appears in the folder. The -fill option says that you wish to have the widget stretch to fill the available space in the folder.
.ts tab configure "f1" -fill both -padx 0.25i -pady 0.25i
Now when you click the left mouse button on "f1", the graph will be displayed in the folder. It will be automatically hidden when another folder is selected. If you click on the right mouse button, the embedded widget will be moved into a toplevel widget of its own. Clicking again on the right mouse button puts it back into the folder. literal magic β¨
If you want to share a page between two different folders, the -command option lets you specify a Tcl command to be invoked whenever the folder is selected. You can reset the -window option for the tab whenever it's clicked.
.ts tab configure "f2" -command {
.ts tab configure "f2" -window ".ts.graph"
}
.ts tab configure "f1" -command {
.ts tab configure "f1" -window ".ts.graph"
}
If you have many folders, you may wish to stack tabs in multiple tiers. The container's -tiers option requests a maximum number of tiers. The default is one tier.
.ts configure -tiers 2
If the tabs can fit in less tiers, the widget will use that many. Whenever there are more tabs than can be displayed in the maximum number of tiers, the container will automatically let you scroll the tabs. You can even attach a scrollbar to the container.
.ts configure -scrollcommand { .sbar set } -scrollincrement 20
.sbar configure -orient horizontal -command { .ts view }
By default tabs are along the top of the container from left to right. But tabs can be placed on any side of the container using the -side option.
# Arrange tabs along the right side of the container.
.ts configure -side right -rotate 270
β SYNTAX β
The container command creates a new window using the pathName argument and makes it into a container widget.
container pathName ?option value?...
Additional options may be specified on the command line or in the option database to configure aspects of the container such as its colors, font, text, and relief. The container command returns its pathName argument. At the time this command is invoked, there must not exist a window named pathName, but pathName's parent must exist.
When first created, a new container contains no tabs. Tabs are added or deleted using widget operations described below. It is not necessary for all the tabs to be displayed in the container window at once; commands described below may be used to change the view in the window. Containers allow scrolling of tabs using the -scrollcommand option. They also support scanning (see the scan operation). Tabs may be arranged along any side of the container window using the -side option.
The size of the container window is determined by the number of tiers of tabs and the sizes of the Tk widgets embedded inside each folder. The widest widget determines the width of the folder. The tallest determines the height. If no folders contain an embedded widget, the size is determined solely by the size of the tabs.
You can override either dimension with the container's -width and -height options.
π CONTAINER OPERATIONS π
Okay bestie, so every single container operation gets called the same way β you give it the widget's pathName, then the operation, then whatever args that operation needs. The general form is literally:
pathName operation ?arg arg ...?
The operation plus the args are what decide the exact behavior of the command. Here are all the operations container widgets have for you π
πΈ pathName cget option
Returns the current value of the configuration option you name in option. And option can be literally any of the values that the configure operation below accepts. Slay, no guessing needed. β¨
πΈ pathName configure ?option? ?value option value ...?
Query or modify the widget's configuration options β the glow-up operation, basically.
- If you pass no option, it returns a list describing all the available options for
pathName(peepTk_ConfigureInfoif you wanna know the format of that list). - If you pass option with no value, the command returns a list describing that one named option β and heads up, this list will be identical to the corresponding sublist of the value you'd get if you specified no option at all.
- If you pass one or more option-value pairs, it modifies those widget option(s) to have the given value(s), and in that case the command returns an empty string. Cute and tidy.
Option and value are described below, so keep scrolling π
-backgroundcolor β Sets the border color of the container.-borderwidthpixels β Sets the width of the 3-D border around the outside edge of the widget. The-reliefoption is what determines how the border gets drawn. The default is2.-commandpattern β Specifies to search for a window whoseWM_COMMANDproperty matches the given pattern (X11 only π§). If no windows match, or more than one window matches, an error is generated. If pattern is the empty string, then no command search is performed. The default is"".-cursorcursor β Specifies the widget's cursor. The default cursor is"".-heightpixels β Specifies the requested height of widget. If pixels is0, then the height is height the embedded window plus the specified borderwidth. The default is0.-highlightbackgroundcolor β Sets the color to display in the traversal highlight region when the container does not have the input focus.-highlightcolorcolor β Sets the color to use for the traversal highlight rectangle that's drawn around the widget when it has the input focus. The default isblack.-highlightthicknesspixels β Sets the width of the highlight rectangle to draw around the outside of the widget when it has the input focus. Pixels is a non-negative value and may have any of the forms acceptable toTk_GetPixels. If the value is zero, no focus highlight is drawn around the widget. The default is2.-namepattern β Specifies to search for a window whoseWM_NAMEproperty matches the given pattern (X11 only π§). If no windows match, or more than one window matches, an error is generated. If pattern is the empty string, then no name search is performed. The default is"".-reliefrelief β Specifies the 3-D effect for the container widget. Relief specifies how the container should appear relative to the widget that it is packed into; for exampleraisedmeans the container should appear to protrude. The default issunken.-takefocusfocus β Provides information used when moving the focus from window to window via keyboard traversal (like Tab and Shift+Tab). If focus is0, that means this window should be skipped entirely during keyboard traversal.1means this window should always receive the input focus. An empty value means the traversal scripts decide whether to focus on the window. The default is1.-widthpixels β Specifies the requested width of the widget. If pixels is0, then the width is the width the embedded window and the specified borderwidth. The default is0.-windowid β Specifies the foreign embedded using its path or X window id.
πΈ pathName find -command|-name pattern
Searches for all windows that match the given pattern. Two flavors, pick your fighter:
- If the
-commandswitch is given, all windows whoseWWM_COMMANDproperty match pattern are returned in a list (X11 only π§). - If the
-nameswitch is given, all windows whoseWWM_NAMEproperty match pattern are returned in a list.
The list returned will contains pairs of the window id and the matching property. Periodt. π
π KEYWORDS π
container, widget
And that's the whole vibe, bestie β you just read the container(n) page from BLT, version 2.5, straight out of the manual. Go embed something iconic π
β¨π¦
π¦ where this page comes from
- nixpkgs unstable: blt 2.5.3
- Copyright 1998 by Bell Labs Innovations for Lucent Technologies
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms