Reputation: 145
I'm writing a GUI, and I want to open multiple windows with same interface and independent. But I when I try to input in one window, and another one shows the same thing, how to make the windows independent? Example:
foreach name {test1 test2} {
namespace eval $name {
variable InputStr
variable wid
proc Display {var} {
variable InputStr
variable wid
set wid .$var
destroy $wid
toplevel $wid
wm title $wid $var
entry $wid.en -textvariable InputStr
pack $wid.en
}
}
${name}::Display $name
}
Why they are dependent? How to solve this problem?
Upvotes: 0
Views: 212
Reputation: 13252
Given an unqualified variable name, the entry widget assumes the variable is a global and uses the same variable in both cases. Try
entry $wid.en -textvariable [namespace current]::InputStr
or
entry $wid.en -textvariable $var\::InputStr
which should be the same thing, given the definitions in the question.
Upvotes: 2