Tcl 如何使用tk_optionMenu程序?

Tcl 如何使用tk_optionMenu程序?,tcl,tcltk,Tcl,Tcltk,我正在尝试用TCL/Tk开发一个GUI,因为它是逐点网格生成软件的“宏语言”。我发现一篇帖子讨论了一个名为tk_optionMenu的程序的使用,该程序可用。问题是我不知道如何调用例程,也不知道如何在选项菜单中输入各种条目。我想要的选项不是数字,而是不同例程的文本。此例程中的信息说明参数为“>=1”,而不是文本。例如,我需要一个选项菜单,以便用户可以选择在网格上使用哪种平滑方法。在我用TCL中的网格格式设置的GUI中,我有几个位置需要使用选项菜单 根据格伦·杰克曼的建议,我尝试了以下方法: #!

我正在尝试用TCL/Tk开发一个GUI,因为它是逐点网格生成软件的“宏语言”。我发现一篇帖子讨论了一个名为
tk_optionMenu
的程序的使用,该程序可用。问题是我不知道如何调用例程,也不知道如何在选项菜单中输入各种条目。我想要的选项不是数字,而是不同例程的文本。此例程中的信息说明参数为“>=1”,而不是文本。例如,我需要一个选项菜单,以便用户可以选择在网格上使用哪种平滑方法。在我用TCL中的网格格式设置的GUI中,我有几个位置需要使用选项菜单

根据格伦·杰克曼的建议,我尝试了以下方法:

#!/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 .
        }
    }
}
当我运行这个程序时,我会得到一个空白框,上面有一些选项,可以将其图标化或关闭。取消对列和行配置信息的注释或注释没有任何区别。使用注释行填充optionMenu与使用
{*}解算器填充optionMenu没有任何区别。所以,有些地方不对劲,我不知道是什么

这里有一个简短的演示:

#!/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
下面是一个简短的演示:

#!/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