Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6205683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:19:05+00:00 2026-05-24T05:19:05+00:00

I have a Tcl script controlling an automated tester. So far it was a

  • 0

I have a Tcl script controlling an automated tester. So far it was a console program that took user input at the command prompt. A colleague wrote a Tk GUI that can be launched by the script. I have never used Tk myself, so I don’t understand a lot of the syntax.

At the beginning of the test the script must get a unit serial number from the operator. This is the function that my colleague wrote to do that:

proc GetSerialNumber {} {
 global gUserInterfaceBarCode

 DisplayMessage "Enter serial number:"

 .c.serialnumberbox configure -state normal

 focus .c.serialnumberbox

 bind .c.serialnumberbox <Return> { set gUserInterfaceBarCode [.c.serialnumberbox get] }

 tkwait variable gUserInterfaceBarCode

 #grid forget .c.serialnumberbox

 .c.serialnumberbox configure -state disabled

}

DisplayMessage is a procedure that simply updates a text label on the GUI.

I don’t like the fact that there is a global variable gUserInterfaceBarCode that is used to hold the serial number. Is there any way to use a local variable instead and have the procedure return that value?

If I understand correctly, if the line tkwait variable gUserInterfaceBarCode is taken out this function will not block until that variable changes. Is this the best way to capture user input from a GUI element?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T05:19:06+00:00Added an answer on May 24, 2026 at 5:19 am

    Fundamentally you need to have a variable to wait on. Unfortunately, the code for the <Return> is executed in a different context (the global context) than the code inside your proc, and there’s no way for that code to address the local variables in your proc.

    However, it doesn’t have to a global variable, per se — it just needs to be globally addressable, by which I mean you could use a namespace variable instead, if that makes you feel better about it:

    namespace eval GetSerialNumber {
        proc GetSerialNumber {} {
    
            DisplayMessage "Enter serial number:"
            .c.serialnumberbox configure -state normal
            focus .c.serialnumberbox
            bind .c.serialnumberbox <Return> { set ::GetSerialNumber::result [.c.serialnumberbox get] }
            tkwait variable ::GetSerialNumber::result
            .c.serialnumberbox configure -state disabled
            return $::GetSerialNumber::result
        }
    }
    
    set serialNum [GetSerialNumber::GetSerialNumber]
    

    Another alternative would be to explicitly delete gUserInterfaceBarCode before returning:

    tkwait variable ::gUserInterfaceBarCode
    set result $::gUserInterfaceBarCode
    unset ::gUserInterfaceBarCode
    return $result
    

    For what it’s worth, the Tk core implementation uses the namespace approach for its own built-in dialog implementations, like the “Open File” dialog box.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a main TCL proc that sources tons of other tcl procs in
I have a tcl script which 'exec' rpmbuild. When doing so, the 'topdir' used
I have a PHP script at the following location C:\wamp\www\tcl\bin\ I am accessing the
Does python have an equivalent to Tcl's uplevel command? For those who don't know,
Is it possible to call Tcl procedures that have function pointers (or callback functions)
I want to create a simple Console in Tcl/Tk I have two problems. First
I need to have two way communication between threads in Tcl and all I
I have some TCL scripts on the server . I am using a client
I wrote a script in tcl to grab links out of the download portion
We have a few Tcl/Tk scripts (because a GUI we use can incorporate macros

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.