comp.lang.tcl
[Top] [All Lists]

Re: Entry and -textvariable

Subject: Re: Entry and -textvariable
From: Aric Bills
Date: Mon, 12 May 2008 22:47:27 -0700 PDT
Newsgroups: comp.lang.tcl

Hi David,

The $cmd you set and whose value you check in your proc is a local
variable.  The $cmd you assigned to your entry widget as -textvariable
is a global variable.  That's why you're seeing the behavior in
question.

To modify the global variable $cmd in your proc, you need to do ONE of
the following things:

* before your first use of the variable cmd, type "global cmd"; this
tells the interpreter that within your proc, $cmd refers to a global
variable rather than a local one.

OR

* before your first use of the variable cmd, type "variable cmd"; this
tells the interpreter that within your proc, $cmd refers to a
namespace variable rather than a local one.  This will only work if
your proc is in the global namespace.

OR

* each time you want to modify the global variable $cmd, use it's
fully-namespace-qualified name: ::cmd (so, [set ::cmd 6], [puts
$::cmd], etc.).

Hope that helps,
Aric

<Prev in Thread] Current Thread [Next in Thread>
Privacy Policy