Support for interactive cell editing with the aid of the Tk core and tile menubutton widgets was added in Tablelist version 5.3.
From the manual page Interactive Cell Editing Using the menubutton Widget:
The temporary embedded menubutton widget used for interactive cell editing will be created with explicitly set values for its -anchor
,-indicatoron
,-justify
,-padx
,-pady
,-relief
, and-textvariable
options. In addition, a menu with its-tearoff
option set to0
and an appropriate script as the value of its-postcommand
option is created and set as the value of the menubutton's-menu
option. ... You can use the script corresponding to the-editstartcommand
tablelist configuration option to set any other options of the menubutton and/or its associated menu. You will, however, need this script in the first place for populating the menu, preferably with radiobutton entries. For every radiobutton entry added to the menu, the Tablelist implementation will make sure that its value (which can be specified by setting the entry's-value
or-label
option) will be displayed in the menubutton as its text when the entry is selected. (...) For menu entries of types other than radiobutton (e.g., for command entries) it is the responsibility of the application to make sure that the selected entry's text will be shown in the menubutton (for example, with the aid of the menu entry's-command
option).
From the manual page Interactive Cell Editing Using the tile menubutton Widget:
The temporary embedded tile menubutton widget used for interactive cell editing will be created with explicitly set values for its -style
and-textvariable
options. In addition, ... (identical to the description above).
Menubuttons versus comboboxes:
Menubuttons and menu entries can be configured to have images, by
using the -image
(or -bitmap
)
option (combined with -compound
if both an image and
text are to be displayed).
With the -command
menu entry option it is easy to
specify a Tcl command to execute when the menu entry is invoked.
Similar functionality for comboboxes is highly dependent on the combobox
widget being used.
Menu entries can be arranged in several columns, by using the
-columnbreak
menu entry option. (Unfortunately,
this feature is no longer supported on Mac OS X Aqua.)
The following sample code snippets are taken from the latest version of
the demo script tileWidgets.tcl
, as contained in the forthcomimg
Tablelist release 5.7:
set dir [file dirname [info script]]
. . .
#
# Create the images "checkedImg" and "uncheckedImg", as well as 16 images of
# names like "img#FF0000", displaying colors identified by names like "red"
#
source [file join $dir images.tcl]
. . .
$tbl columnconfigure 10 -name color -editable yes -editwindow ttk::menubutton \
-formatcommand emptyStr
. . .
proc editStartCmd {tbl row col text} {
set w [$tbl editwinpath]
switch [$tbl columncget $col -name] {
. . .
color {
#
# Populate the menu and make sure the menubutton will display the
# color name rather than $text, which is "", due to -formatcommand
#
set menu [$w cget -menu]
foreach name $::colorNames {
$menu add radiobutton -compound left \
-image img$::colors($name) -label $name
}
$menu entryconfigure 8 -columnbreak 1
return [$tbl cellcget $row,$col -text]
}
}
return $text
}
proc editEndCmd {tbl row col text} {
switch [$tbl columncget $col -name] {
. . .
color {
#
# Update the image contained in the cell
#
$tbl cellconfigure $row,$col -image img$::colors($text)
}
}
return $text
}