SWAPLIST(n)
π swaplist β the manual, but make it make sense
okay bestie so this is swaplist(n), a Tcl manpage from the tklib fam, and I promise it's actually cute once you see it. it's a dialog with two listboxes and you justβ¦ move stuff between them. that's the whole vibe. icon behavior honestly. π«Ά
β¨ NAME β¨
swaplist β a dialog which allows a user to move options between two lists π
πΈ SYNOPSIS πΈ
package require Tcl 8.4
package require Tk 8.4
package require swaplist ?0.1?
::swaplist::swaplist pathName variable completeList selectedList
?options?
no cap, that ?0.1? is optional-version notation, not me being shady about it π
π¦ DESCRIPTION π¦
bestie. it's so simple. this package hands you a dialog made of 2 listboxes, plus buttons to shuffle items between them and to reorder the right-hand list. two lists. buttons. slay. β¨
::swaplist::swaplist pathName variable completeList selectedList ?options?
creates a dialog which presents the user with a pair of listboxes. π
the way it works: items get selected by using the buttons to move them over to the right list. then, when the dialog closes, the contents of the right list get dropped into the variable. main character energy tbh.
the command returns a boolean telling you whether the user pressed OK or not β 1 for yes bestie, 0 for nope.
and about placement π β if -geometry is not specified, the dialog centers itself in its parent toplevel, unless its parent is ., in which case the dialog centers itself on the screen instead. tiny detail, big difference, iykyk.
π Options:
-embedβ if this flag is supplied, the procedure will create a swaplist widget namedpathName, with thevariableset as thelistvariablefor the right side listbox. heads up though: this flag will also cause the-titleand-geometryflags to be ignored. they simply do not get an invite to this party π-reorderβ boolean specifying if buttons allowing the user to change the order of the right listbox should appear or not. defaults totrue. yes queen, reorder the list.-titleβ sets the title of the dialog window. defaults to"Configuration".-llabelβ sets the heading above the left list. defaults to"Available:".-rlabelβ sets the heading above the right list. defaults to"Selected:".-lbuttontextβ sets the text on the "move left" button. defaults to"<<".-rbuttontextβ sets the text on the "move right" button. defaults to">>".-ubuttontextβ sets the text on the "move up" button. defaults to"Move Up".-dbuttontextβ sets the text on the "move down" button. defaults to"Move Down".-geometryβ sets the geometry of the dialog window. π
π EXAMPLE π
okay here's the moment you've been waiting for, the actual code, no notes:
package require swaplist
namespace import swaplist::*
if {[swaplist .slist opts "1 2 3 4 5 6 7 8 9" "1 3 5"]} {
puts "user chose numbers: $opts"
}
see like β "1 2 3 4 5 6 7 8 9" is the complete list, "1 3 5" is what's preselected, and if they hit OK you get their picks in $opts. and if they don't, the if just doesn't fire. chef's kiss. π
π BUGS, IDEAS, FEEDBACK π
ngl, this document β and the package it describes β will undoubtedly contain bugs and other problems. it's giving "we're all just doing our best." π
please report such in the category swaplist of the Tklib Trackers at http://core.tcl.tk/tklib/reportlist.
please also report any ideas for enhancements you may have for either the package and/or this documentation. we want the glow-up, we welcome the glow-up. π«Άβ¨
π§ KEYWORDS π§
dialog, disjointlistbox, listbox
π CATEGORY π
Widget
okay that's the whole page, you ate that. π and for the cute sign-off: this little icon is from tklib, version 0.1 β go forth and swap your lists, bestie. πβ¨π
π¦ where this page comes from
- alpine 3.24: tk-lib-doc 0.7-r0 Β· TCL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms