top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What namespace is used to evaluate commands or access variables for a Tk widget?

+1 vote
387 views
What namespace is used to evaluate commands or access variables for a Tk widget?
posted May 15, 2014 by Anshika Utadi

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Ordinary variable names and code fragments are evaluated in the global namespace. This is consistent with vanilla Tcl/Tk, and provides backward-compatibility with existing Tcl/Tk applications.

Consider the following example:

  proc show {mesg} {
        puts "global: $mesg"
    }
    namespace foo {
        variable x
        proc show {mesg} {
            puts "foo: $mesg"
        }
    checkbutton .cb -variable x -command {show "state = $x"}
}

The checkbutton .cb is created within namespace ::foo. However, its -variable and -command options are ordinary strings, and they are evaluated in the global namespace. The name "x" refers to the variable "::x", and the command "show" refers to "::show".

If a widget is meant to use commands and variables in the local namespace, it must be configured with scoped values as follows:

namespace foo {
    .cb configure \
        -variable [scope x] \
        -command [code {show "state = $x"}]
}
answer May 16, 2014 by Samardeep Acharya
Similar Questions
+2 votes

We develop embedded software for 32-bit micros using Windows as the development platform.

We are seeking a general purpose scripting language to automate certain tasks, like cleaning out certain directories of certain types of files in preparation for ZIP'ing, generating certain source files automatically, etc.

Selection criteria:

a)Should be able to compile the script interpreter as a monolithic executable (no .DLL dependencies, etc.) for easy versioning and distribution of the script interpreter. (Note that I'm not asking that the script be a single executable, just the interpreter. To run a script you'd need both the script and the interpreter. The script would be a text file, and the interpreter would be a single .EXE.)

b)Should be extensible, in that one could add commands or library functions to the script interpreter in C (for efficiency), and the whole script interpreter could again consist of a single executable with no other dependencies. (Note that I'm not asking that the script be a single executable, just the interpreter. To run a script you'd need both the script and the interpreter. The script would be a text file, and the interpreter would be a single .EXE.)

c)Should be able to spawn compilers and capture the output, do file I/O, and all the other minor expected stuff.

d)Graphical capability would be nice.

I know that Tcl/Tk would do all of the above, but what about Python or any other alternatives?

...