0

我正在尝试使用 TCL/Tk 开发 GUI,因为那是 Pointwise 网格生成软件的“宏语言”。我发现一篇帖子讨论了一个名为的过程的使用,该过程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 而不是{*}solvers也没有任何区别。所以,有些东西是不正确的,我不知道是什么。

4

1 回答 1

2

这是一个简短的演示:

#!/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
于 2018-11-15T21:08:26.767 回答