Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
textvariables for entries can't be global?

Posted by hell_squirrel (hell_squirrel), 4 December 2007
Hello all

I'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:
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.

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.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho