Reputation: 27
I am trying to develop a GUI with TCL/Tk because that is the "macro language" of Pointwise, mesh generation software. I found a posting that discusses the use of a procedure called tk_optionMenu
which is available here. The problem is that I do not understand how to call the routine, nor how to get various entries into the option menu. The options I want are not numbers, but text for different routines. The information in this routine notes that the arguments are ">=1", not text. For example, I want an option menu so a user can choose which smoothing method to use on a mesh. In my GUI which I am setting up with grid formatting in TCL, I have several locations I want to use an option menu.
Using what Glenn Jackman suggested, I tried the following:
#!/usr/bin/wish
# the next line restarts using wish \
#exec wish "$0" "$@"
# interface generated by SpecTcl version 1.2 from /home/hh-eagle/ab/salter/bin/src/GLYPH/PrismEditor/GUI/PE_v01.ui
# root is the parent window for this user interface
package require Tk
proc PE_v01_ui {root args} {
# this treats "." as a special case
if {$root == "."} {
set base ""
} else {
set base $root
}
label $base.solver \
-text {Solver:}
set solvers {TriSmooth QuadSmooth VolSmooth K_lineSmooth}
tk_optionMenu $base.solvers activeSolver {*}$solvers
# Add contents to menus
# $base.solvers.menu add radiobutton -label TriSmooth
# $base.solvers.menu add radiobutton -label QuadSmooth
# $base.solvers.menu add radiobutton -label VolSmooth
# $base.solvers.menu add radiobutton -label K_lineSmooth
# Geometry management
grid $base.solver -in $root -row 2 -column 6
grid $base.solvers -in $root -row 2 -column 7 \
-columnspan 2
# Resize behavior management
# grid rowconfigure $root 1 -weight 0 -minsize 30 -pad 0
# grid rowconfigure $root 2 -weight 0 -minsize 30 -pad 0
# grid rowconfigure $root 3 -weight 0 -minsize 30 -pad 0
# grid rowconfigure $root 4 -weight 0 -minsize 30 -pad 0
# grid rowconfigure $root 5 -weight 0 -minsize 30 -pad 0
# grid rowconfigure $root 6 -weight 0 -minsize 30 -pad 0
# grid rowconfigure $root 7 -weight 0 -minsize 30 -pad 0
# grid rowconfigure $root 8 -weight 0 -minsize 30 -pad 0
# grid rowconfigure $root 9 -weight 0 -minsize 30 -pad 0
# grid columnconfigure $root 1 -weight 0 -minsize 30 -pad 0
# grid columnconfigure $root 2 -weight 0 -minsize 30 -pad 0
# grid columnconfigure $root 3 -weight 0 -minsize 30 -pad 0
# grid columnconfigure $root 4 -weight 0 -minsize 30 -pad 0
# grid columnconfigure $root 5 -weight 0 -minsize 30 -pad 0
# grid columnconfigure $root 6 -weight 0 -minsize 30 -pad 0
# grid columnconfigure $root 7 -weight 0 -minsize 2 -pad 0
# grid columnconfigure $root 8 -weight 0 -minsize 2 -pad 0
# grid columnconfigure $root 9 -weight 0 -minsize 30 -pad 0
# grid columnconfigure $root 10 -weight 0 -minsize 30 -pad 0
# additional interface code
# end additional interface code
}
# Allow interface to be run "stand-alone" for testing
catch {
if [info exists embed_args] {
# we are running in the plugin
PE_v01_ui .
} else {
# we are running in stand-alone mode
if {$argv0 == [info script]} {
wm title . "Testing PE_v01_ui"
PE_v01_ui .
}
}
}
When I run this, I get a blank box with the options at the top to iconify or dismiss it. Uncommenting or commenting the column and row configuration information made no difference. Populating the optionMenu using the commented lines as opposed to {*}solvers
also didn't make any difference. So, something isn't correct, and I have no idea what.
Upvotes: 0
Views: 393
Reputation: 246774
Here's a short demo:
#!/usr/bin/env tclsh
package require Tk
set choices {foo bar baz qux "None of the above"}
label .menuLabel -text "Make a selection: "
# "choice" is a global variable
tk_optionMenu .menu choice {*}$choices
label .displayLabel -text "You chose: "
label .display -textvariable choice
grid .menuLabel .menu
grid .displayLabel .display
Upvotes: 2