| |||||||||||
textvariables for entries can't be global? Posted by hell_squirrel (hell_squirrel), 4 December 2007 Hello allI've got a bit a confusing problem. First I describe what the programm does: It displays some values, which the user can change. when he accepted it the programm writes a file. if the file does already exist, read the values and display them. The funny thing is, my programm does properly read and write the values, but the entryboxes don't display anything except the initializing values. When I change the value in one entrybox and give the command to write the file, it doesn't write the new value. The variables and entryboxes are created within the same loop out of a list, I let the programm write out every entrypath and variable to use as textvariable and there was no mistake. I tried to change the value directly from a button, but it didn't work either, it is like they don't have a textvariable. By the way, the here is the codepart which should create the entryboxes foreach {entrypath variable initvalue} $list { global $variable set $variable $initvalue eval entry $entrypath -textvariable $variable } Can anyone help me? sorry for any grammatical and orthographical mistake Posted by admin (Graham Ellis), 4 December 2007 Text variables can have their contents changed by the widget so you need to specify the name of the variable as you set them up. And if you have a variable name within a variable (as you appear), then that won't change later. The variable is expanded at creation time .... which I think is confirming what you're telling me.Quite a well know catch, this one ... the solution if often to defer execution using { to } (and NOT " to " ... but I'm not sure how it is in this particular example. I'm a long way from base this week so don't have my usual tools and books at hand! Posted by hell_squirrel (hell_squirrel), 5 December 2007 on 12/04/07 at 16:22:00, Graham Ellis wrote:
So the problem is because the variable names are specified in a list? But why does it matter, I don't declare them in the list... Okey, I have to enclose something in curly brackets, I have about 700 lines of code, I hope I enclose the right lines I just implemented a simplified example of my project, and it worked great, I searched for differences in the original project, but I haven't found any. Here is the code: proc create {vlist} { foreach {variable entry initvalue} $vlist { global $variable set $variable $initvalue entry $entry -textvariable $variable pack $entry } button .btn -text write -command {write} pack .btn } proc change {} { global variables foreach variable $variables { global $variable set $variable "changed! VICTORY!!" } } proc main {} { global variables set variableEntry "var1 {.entry1} hey var2 {.entry2} hou" set variables "var2 var1" create $variableEntry change } proc write {} { global variables set file [open out.txt w+] foreach variable $variables { global $variable eval puts $file $$variable } close $file } main Don't ask why I specified the variables again in the variable variables in an other order (weirdest phrase ever). it is there to eliminate other problems I had in the original project and survived the simplification to show the situation. Before I forget it again: I let the "big brother" write out every variable, its current value and other parameters in different procedures. The variable names are ok, the variables are set to the right entry and the change of the value has no mistake. The entry just doesn't update, as if only the value of the variable would be given to the entry than the variable name. I hope this helps. This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |