How to pass data enter in a text field

  • Joe Klemmer

    Joe Klemmer - 2002-06-14

    I am trying to use SpecTcl as a front-end for non-gui programs.  I started with a simple app in SpecTcl that has a label,  text & two buttons (one to exec the program and one to exit).  I can't figure out what I need to do to get the data entered into the text to be passed to the command in the exec.  There doesn't seem to be a way to set a variable for the text.  There's a setting of textvariabel entry in the button properties but if I set it to "fname", for example, and then have "exec mytestapp $fname" command setting it works except it will pass the data in the text of the properties of the button to the program.

    I will attach the generated tcl code so you can see what I mean.

    #! /bin/sh
    # the next line restarts using wish \ exec wish "$0" "$@"
    # interface generated by SpecTcl version 1.2 from /home/klemmerj/src/scripts/test-shell.ui
    #   root     is the parent window for this user interface

    proc test-shell_ui {root args} {

        # this treats "." as a special case

        if {$root == "."} {
            set base ""
        } else {
            set base $root
        label $base.label#1 \         -text {Test Call to shell}
        catch {
            $base.label#1 configure \             -font -*-Helvetica-Bold-R-Normal-*-*-180-*-*-*-*-*-*

        text $base.text#2 \         -height 1 \         -width 1

        button $base.button#3 \         -command {exec mytestapp $fname} \         -default active \         -text Submit \         -textvariable fname

        button $base.button#4 \         -command exit \         -text Cancel

        # Add contents to menus

        # Geometry management

        grid $base.label#1 -in $root    -row 1 -column 1  \         -columnspan 2 \         -sticky nesw
        grid $base.text#2 -in $root    -row 2 -column 1  \         -columnspan 2 \         -sticky nesw
        grid $base.button#3 -in $root    -row 3 -column 1
        grid $base.button#4 -in $root    -row 3 -column 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 columnconfigure $root 1 -weight 0 -minsize 114 -pad 0
        grid columnconfigure $root 2 -weight 0 -minsize 124 -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
        test-shell_ui .
        } else {
        # we are running in stand-alone mode
        if {$argv0 == [info script]} {
            wm title . "Testing test-shell_ui"
            test-shell_ui .

    Any help would be highly appreciate it.  If you could reply directly to at I'll give you 20% of the first million I make if I hit the lottery.  ;-)


    • Joe Klemmer

      Joe Klemmer - 2002-06-14

      Nevermind.  As is always the case, I figured out that it isn't a text  I need but an entry.  All is working just the way I need it.

    • Nobody/Anonymous

      Dear Joe

      The text widget is so complex that it often doesn't make sense to have a
      -textvariable attribute. If you want this, use the entry widget instead and
      use its -textvariable attribute instead of the one on the button. If you must
      use the text widget you need to use the text widget "get" subcommand, but I
      have a feeling that this will be very tricky.



Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks