Hi,
I'm having a small problem writing a textvariable to a file.
Here is what im trying to do. User enters username and password in a label. The data gets stored and writen to a file. Here is the code i have.
[code]
global MasterUser
global MasterPassword
label .tb.luser -text "Enter username : "
entry .tb.enterUser -relief sunken -bd 4 -textvariable MasterUser
label .tb.lpassw -text "Enter password : "
entry .tb.enterPass -relief sunken -bd 4 -textvariable MasterPassword
set fout [open users.txt a]
puts $fout "Hello"
puts $fout $MasterUser
puts $fout "$MasterPassword"
close $fout
button .tb.subPass -text "Submit" -command Startproc
pack .tb
pack .tb.luser
pack .tb.enterUser
pack .tb.lpassw
pack .tb.enterPass
pack .tb.subPass
[/code]
When i run this example, the "hello" gets written to the file, the MasterUser and MasterPassword line spaces are there, but the actual variable contents are not written.
Does anyone know why the variable contents are not visible in the file??
Thanks,
Philip.
The problem is that you write the variables out before anything is put in them. The write to file should occur on the command invocation of the button. IOW, in Startproc (not defined).
Hi Jeffh,
Thanks for replying. I've changed the button to this:
[code]
button .tb.subPass -text "Submit" -command { set fout [open junk.txt a]
puts $fout "Hello"
puts $fout "$MasterUser"
puts $fout $MasterPassword
close $fout}
[/code]
This seems to work perfectly. But now where can i put my StartProc. As the name suggests this is a proc that i want to call. I placed on a separate line underneath the file close. But it gives an error. Is it possible to define it within the button aswell?
My question here basically is, how can i make the button do 2 operations
1. Copy variables to file (already does this, works great)
2. Launch into the Startproc procedure.(after the variables are copied)
Thanks,
Philip
Ok, well, just to let people know, i didn't get this working but i found a different way around it. So all's good. :)