How do I use the tk_optionMenu procedure?












0















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.










share|improve this question





























    0















    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.










    share|improve this question



























      0












      0








      0








      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.










      share|improve this question
















      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.







      tcl tcltk






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 16 '18 at 16:23







      Stephen Alter

















      asked Nov 15 '18 at 19:46









      Stephen AlterStephen Alter

      1713




      1713
























          1 Answer
          1






          active

          oldest

          votes


















          2














          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





          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53326901%2fhow-do-i-use-the-tk-optionmenu-procedure%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2














            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





            share|improve this answer




























              2














              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





              share|improve this answer


























                2












                2








                2







                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





                share|improve this answer













                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






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 15 '18 at 21:08









                glenn jackmanglenn jackman

                170k26147240




                170k26147240
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53326901%2fhow-do-i-use-the-tk-optionmenu-procedure%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Florida Star v. B. J. F.

                    Danny Elfman

                    Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues