iwidgets::tabset(1)

๐Ÿ’– iwidgets::tabset โ€” the whole vibe ๐Ÿ’–

okay bestie, welcome to iwidgets::tabset(1), straight outta [incr Widgets] โœจ this one's a long one so buckle up, we're doing it in parts ๐Ÿซถ


๐ŸŽ€ NAME ๐ŸŽ€

iwidgets::tabset โ€” create and manipulate tabs as as set

yes the original says "as as set", we keep it, no notes ๐Ÿ’…

โœจ SYNOPSIS โœจ

iwidgets::tabset pathName ?options?

๐Ÿฆ‹ INHERITANCE ๐Ÿฆ‹

itk::Widget <- iwidgets::Tabset


๐ŸŒธ STANDARD OPTIONS ๐ŸŒธ

  • background
  • font
  • selectBackground
  • cursor
  • foreground
  • selectForeground
  • disabledForeground
  • height
  • width

See the options manual entry for the full deets on all these standard options, bestie ๐Ÿ‘‘


๐Ÿ’… WIDGET-SPECIFIC OPTIONS ๐Ÿ’…

These are the extra options, the ones that make a tabset actually a tabset. Every one of them has a Name, a Class, and a Command-Line Switch, and I'm giving you all three every single time because we do not skip details in this house ๐Ÿซถ

  • -angle โ€” Name: angle, Class: Angle, Command-Line Switch: -angle

Specifes the angle of slope from the inner edge to the outer edge of the tab. An angle of 0 specifies square tabs. Valid ranges are 0 to 45 degrees inclusive. Default is 15 degrees. If tabPos is e or w, this option is ignored ๐Ÿ™ˆ.

  • -backdrop โ€” Name: backdrop, Class: Backdrop, Command-Line Switch: -backdrop

Specifies a background color to use when filling in the area behind the tabs ๐ŸŽจ.

  • -bevelamount โ€” Name: bevelAmount, Class: BevelAmount, Command-Line Switch: -bevelamount

Specifes the size of tab corners. A value of 0 with angle set to 0 results in square tabs. A bevelAmount of 4, means that the tab will be drawn with angled corners that cut in 4 pixels from the edge of the tab. The default is 0.

  • -command โ€” Name: command, Class: Command, Command-Line Switch: -command

Specifes the prefix of a Tcl command to invoke to change the view in the widget associated with the tabset. When a user selects a tab, a Tcl command is invoked. The actual command consists of this option followed by a space and a number. The number is the numerical index of the tab that has been selected ๐Ÿ”ฅ.

  • -equaltabs โ€” Name: equalTabs, Class: EqualTabs, Command-Line Switch: -equaltabs

Specifies whether to force tabs to be equal sized or not. A value of true means constrain tabs to be equal sized. A value of false allows each tab to size based on the text label size. The value may have any of the forms accepted by the Tcl_GetBoolean, such as true, false, 0, 1, yes, or no.

For horizontally positioned tabs (tabPos is either s or n), true forces all tabs to be equal width (the width being equal to the longest label plus any padX specified). Horizontal tabs are always equal in height.

For vertically positioned tabs (tabPos is either w or e), true forces all tabs to be equal height (the height being equal to the height of the label with the largest font). Vertically oriented tabs are always equal in width ๐Ÿ“.

  • -gap โ€” Name: gap, Class: Gap, Command-Line Switch: -gap

Specifies the amount of pixel space to place between each tab. Value may be any pixel offset value. In addition, a special keyword overlap can be used as the value to achieve a standard overlap of tabs. This value may have any of the forms acceptable to Tk_GetPixels ๐ŸŒˆ.

  • -margin โ€” Name: margin, Class: Margin, Command-Line Switch: -margin

Specifies the amount of space to place between the outside edge of the tabset and the outside edge of its tabs. If tabPos is s, this is the amount of space between the bottom edge of the tabset and the bottom edge of the set of tabs. If tabPos is n, this is the amount of space between the top edge of the tabset and the top edge of the set of tabs. If tabPos is e, this is the amount of space between the right edge of the tabset and the right edge of the set of tabs. If tabPos is w, this is the amount of space between the left edge of the tabset and the left edge of the set of tabs. This value may have any of the forms acceptable to Tk_GetPixels โœจ.

  • -padx โ€” Name: padX, Class: PadX, Command-Line Switch: -padx

Specifies a non-negative value indicating how much extra space to request for a tab around its label in the X-direction. When computing how large a window it needs, the tab will add this amount to the width it would normally need The tab will end up with extra internal space to the left and right of its text label. This value may have any of the forms acceptable to Tk_GetPixels ๐ŸŽ€.

  • -pady โ€” Name: padY, Class: PadY, Command-Line Switch: -pady

Specifies a non-negative value indicating how much extra space to request for a tab around its label in the Y-direction. When computing how large a window it needs, the tab will add this amount to the height it would normally need The tab will end up with extra internal space to the top and bottom of its text label. This value may have any of the forms acceptable to Tk_GetPixels ๐ŸŽ€.

  • -raiseselect โ€” Name: raiseSelect, Class: RaiseSelect, Command-Line Switch: -raiseselect

Specifes whether to slightly raise the selected tab from the rest of the tabs. The selected tab is drawn 2 pixels closer to the outside edge of the tabset than the unselected tabs. A value of true says to raise selected tabs, a value of false turns this off. The default is false. The value may have any of the forms accepted by the Tcl_GetBoolean, such as true, false, 0, 1, yes, or no ๐Ÿ‘‘.

  • -start โ€” Name: start, Class: Start, Command-Line Switch: -start

Specifies the amount of space to place between the left or top edge of the tabset and the starting edge of its tabs. For horizontally positioned tabs, this is the amount of space between the left edge of the tabset and the left edge of the first tab. For vertically positioned tabs, this is the amount of space between the top of the tabset and the top of the first tab. This value may change if the user performs a MButton-2 scroll on the tabs. This value may have any of the forms acceptable to Tk_GetPixels ๐ŸŒ€.

  • -state โ€” Name: state, Class: State, Command-Line Switch: -state

Sets the active state of the tabset. Specifying normal allows all tabs to be selectable. Specifying disabled disables the tabset causing all tabs to be drawn in the disabledForeground color ๐Ÿ’€.

  • -tabborders โ€” Name: tabBorders, Class: TabBorders, Command-Line Switch: -tabborders

Specifies whether to draw the borders of tabs that are not selected. Specifying true (the default) draws these borders, specifying false draws only the border around the selected tab. The value may have any of the forms accepted by the Tcl_GetBoolean, such as true, false, 0, 1, yes, or no ๐Ÿ–ผ๏ธ.

  • -tabpos โ€” Name: tabPos, Class: TabPos, Command-Line Switch: -tabpos

Specifies the location of the set of tabs in relation to another widget. Must be n, s, e, or w. Defaults to s. North tabs open downward, South tabs open upward. West tabs open to the right, east tabs open to the left ๐Ÿงญ.


๐ŸŒŸ DESCRIPTION ๐ŸŒŸ

The iwidgets::tabset command creates a new window (given by the pathName argument) and makes it into a tabset widget. Additional options, described above may be specified on the command line or in the option database to configure aspects of the tabset such as its colors, font, and text. The iwidgets::tabset 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 โœ‹.

A tabset is a widget that contains a set of Tab buttons. It displays these tabs in a row or column depending on it tabpos. When a tab is clicked on, it becomes the only tab in the tab set that is selected. All other tabs are deselected. The Tcl command prefix associated with this tab (through the command tab configure option) is invoked with the tab index number appended to its argument list. This allows the tabset to control another widget such as a Notebook ๐Ÿ’–.


๐Ÿ—‚๏ธ TABS ๐Ÿ—‚๏ธ

Tabs are drawn to appear attached to another widget. The tabset draws an edge boundary along one of its edges. This edge is known as the attachment edge. This edge location is dependent on the value of tabPos. For example, if tabPos is s, the attachment edge wil be on the top side of the tabset (in order to attach to the bottom or south side of its attached widget). The selected tab is draw with a 3d relief to appear above the other tabs. This selected tab "opens" toward attachment edge ๐ŸŽญ.

Tabs can be controlled in their location along the edges, the angle that tab sides are drawn with, gap between tabs, starting margin of tabs, internal padding around labels in a tab, the font, and its text or bitmap โœจ.


๐Ÿ› ๏ธ WIDGET-SPECIFIC METHODS ๐Ÿ› ๏ธ

The iwidgets::tabset command creates a new Tcl command whose name is pathName. This command may be used to invoke various operations on the widget. It has the following general form:

pathName option ?arg arg ...?

option and the args determine the exact behavior of the command.

Many of the widget commands for a tabset take as one argument an indicator of which tab of the tabset to operate on. These indicators are called indexes and may be specified in any of the following forms:

  • number โ€” Specifies the tab numerically, where 0 corresponds to the first tab in the tab set, 1 to the second, and so on.
  • select โ€” Specifies the currently selected tab's index. If no tab is currently selected, the value -1 is returned.
  • end โ€” Specifes the last tab in the tabset's index. If the tabset is empty this will return -1.
  • pattern โ€” If the index doesn't satisfy any of the above forms, then this form is used. Pattern is pattern-matched against the label of each tab in the tabset, in order from the first to the last tab, until a matching entry is found. The rules of Tcl_StringMatch are used.

............................................................

The following commands are possible for tabset widgets:

  • pathName add ?option value option value ...? โ€” bestie, this adds a brand-new tab at the very end of the tabset ๐ŸŽ€. It hands you back the child site pathName. And if you passed extra arguments after it? Those are the options, and here's every single one of them:
    • -angle value โ€” sets the angle of the slope going from the inner edge to the outer edge of the tab. An angle of 0 gives you square tabs. Valid range is 0 to 45 degrees inclusive. Default is 15 degrees. If you set this to an empty string (which is the default), then the angle option of the whole tabset gets used instead. ๐Ÿ’…
    • -background value โ€” the background color for showing tabs when they're in their normal state (aka unselected). Empty string (the default) means it falls back to the background option of the overall tabset.
    • -bevelamount value โ€” the size of the tab corners. 0 with angle set to 0 gives you square tabs. A bevelAmount of 4 means the tab gets drawn with angled corners that cut in 4 pixels from the edge of the tab. Default is 0. Ngl this one is generally only set at the tabset configuration level โ€” tabs normally want to share the same bevelAmount.
    • -bitmap value โ€” if label is a non-empty string, this specifies a bitmap to display in the tab. The bitmap can be any of the forms accepted by Tk_GetBitmap. โœจ
    • -disabledforeground value โ€” the foreground color for drawing tab labels when tabs are in their disable state. Empty string (the default) โ†’ the disabledforeground option of the overall tabset gets used.
    • -font value โ€” the font used when drawing the label on a tab. If it's an empty string, then the font option of the overall tabset is used.
    • -foreground value โ€” the foreground color for drawing tab labels when tabs are in their normal unselected state. Empty string (the default) โ†’ the foreground option of the overall tabset.
    • -image value โ€” if label is a non-empty string, this specifies an image to display in the tab. The image has to have been created with the image create command. Typically, if image is specified it overrides the other options that specify a bitmap or textual value for the widget; you can reset image to an empty string to re-enable the bitmap or text display. ๐Ÿฆ‹
    • -label value โ€” a text string placed in the tab's label. If you set this, the bitmap option gets overridden and this is used instead. This label also acts as an extra identifier used to reference the tab, and it can be used as the index value in widget commands. iykyk ๐Ÿ‘‘
    • -selectbackground value โ€” the background color for displaying the selected tab. Empty string (the default) โ†’ the selectBackground option of the overall tabset.
    • -selectforeground value โ€” the foreground color for displaying the selected tab. Empty string (the default) โ†’ the selectForeground option of the overall tabset.
    • -padx value โ€” a non-negative value for how much extra space the tab requests around its label in the X-direction. When it's computing how big a window it needs, the tab adds this amount to the width it would normally need, so it ends up with extra internal space to the left and right of its text label. The value can be any form acceptable to Tk_GetPixels. If it's an empty string (the default), then the padX option of the overall tabset is used.
    • -pady value โ€” a non-negative value for how much extra space the tab requests around its label in the Y-direction. Same deal: the tab adds this to the height it would normally need, giving it extra internal space above and below its text label. Any form acceptable to Tk_GetPixels works. Empty string (the default) โ†’ the padY option of the overall tabset is used.
    • -state value โ€” sets the state of the tab. normal makes this tab selectable. disabled disables it, which draws its tab label in the disabledForeground color, and the tab won't respond to events until the state is set back to normal. ๐Ÿ™ˆ
  • pathName configure ?option? ?value option value ...? โ€” query or modify the configuration options of the widget. If you give it no option, it returns a list describing all the available options for pathName (peep Tk_ConfigureInfo for the format of that list). If you give it an option with no value, it returns a list describing just that one named option โ€” and that list will be identical to the matching sublist of what you'd get with no option specified. And if you hand it one or more option-value pairs, it modifies the given widget option(s) to have the given value(s), and in that case the command returns an empty string. Option can be any of the values accepted by the iwidgets::tabset command. ๐Ÿ’œ
  • pathName delete index1 ?index2? โ€” deletes every tab between index1 and index2, inclusive. If index2 is left out, it defaults to index1. Returns an empty string. Bye bestie ๐Ÿ‘‹
  • pathName index index โ€” returns the numerical index corresponding to index.
  • pathName insert index ?option value option value ...? โ€” inserts a new tab into the tabset before the tab specified by index. The extra arguments are the same as for the add command. Returns the tab's pathName. ๐ŸŒธ
  • pathName next โ€” advances the selected tab to the next tab (the order is determined by insertion order). If the currently selected tab is the last one in the tabset, the selection wraps around to the first tab. It behaves exactly as if the user selected the next tab.
  • pathName tabconfigure index ?option? ?value? โ€” just like the configure command, except this one applies to the options for an individual tab, whereas configure applies to the options for the tabset as a whole. Options can be any of the values accepted by the add widget command. If options are specified, they get modified as indicated in the command and the command returns an empty string. If no options are specified, it returns a list describing the current options for tab index (see Tk_ConfigureInfo for the format of this list).
  • pathName prev โ€” moves the selected tab to the previous tab (order determined by insertion order, same as always). If the currently selected tab is the first tab in the tabset, the selection wraps around to the last tab in the tabset. It behaves as if the user selected the previous tab. ๐Ÿ”ฅ
  • pathName select index โ€” selects the tab specified by index as the currently selected tab. It behaves as if the user selected the new tab. slay ๐Ÿ’…

๐ŸŒˆ EXAMPLE ๐ŸŒˆ

Okay bestie, here's the whole thing in action โ€” a tabset with two tabs plus a listbox that the tabset controls. And plot twist: selecting an item from the list also selects the corresponding tab. Mutual. Reciprocal. It's giving healthy relationship ๐Ÿ’–

package require Iwidgets 4.0
# Define a proc that knows how to select an item
# from a list given an index from the tabset -command callback.
  proc selectItem { item } {
    .l selection clear [.l curselection]
    .l selection set $item
    .l see $item
}

# Define a proc that knows how to select a tab
# given a y pixel coordinate from the list..
  proc selectTab { y } {
    set whichItem [.l nearest $y]
    .ts select $whichItem
}

# Create a listbox with two items (one and two)
# and bind button 1 press to the selectTab procedure.
  listbox .l -selectmode single -exportselection false
  .l insert end one
  .l insert end two
  .l selection set 0
  pack .l
  bind .l <ButtonPress-1> { selectTab %y }

# Create a tabset, set its -command to call selectItem
# Add two labels to the tabset (one and two).
  iwidgets::tabset .ts -command selectItem
  .ts add -label 1
  .ts add -label 2
  .ts select 0
  pack .ts -fill x -expand no

Let's break down the girl math ๐Ÿงฎโœจ

  • package require Iwidgets 4.0 โ€” load the goods first, always.
  • proc selectItem { item } โ€” a proc that knows how to select an item from a list when it's handed an index from the tabset -command callback. It clears the old selection, sets the new one, and .l see $item scrolls it into view. Chef's kiss.
  • proc selectTab { y } โ€” a proc that knows how to select a tab when it's handed a y pixel coordinate from the list. It grabs .l nearest $y, then .ts select $whichItem. Coordinated. Iconic.
  • listbox .l -selectmode single -exportselection false โ€” one listbox, single-select only (we're monogamous here), and -exportselection false so it doesn't fight over the X selection.
  • Then .l insert end one, .l insert end two, .l selection set 0, pack .l โ€” boom, populated and packed.
  • bind .l <ButtonPress-1> { selectTab %y } โ€” click that mouse button and we're passing %y straight into selectTab. Delulu? No. Working. ๐Ÿ’…
  • iwidgets::tabset .ts -command selectItem โ€” the tabset arrives, and its -command points at selectItem.
  • .ts add -label 1, .ts add -label 2, .ts select 0 โ€” two labels, and tab zero gets the spotlight first.
  • pack .ts -fill x -expand no โ€” fill across, but no expanding. Know your boundaries, queen.

๐Ÿซถ AUTHOR ๐Ÿซถ

Bill W. Scott โ€” the mastermind, the blueprint, the moment. Respect was paid. ๐Ÿ‘‘


๐Ÿ”ฅ KEYWORDS ๐Ÿ”ฅ

tab tabset notebook tabnotebook


And that's a wrap on this page, bestie โ€” brought to you by Tk and the one and only iwidgets::tabset(1). Go forth and tab responsibly. No cap. ๐Ÿฆ‹โœจ๐Ÿ’œ

๐Ÿ“ฆ where this page comes from