Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

save and load in TK

Status
Not open for further replies.

frywonton

Technical User
Aug 31, 2011
3
0
0
US
Hi Experts:

I am trying to do a load the file content from a file in tk. Here is a snippet of my load/save steps:
1) A form to
a)Enter Name:
b) Address:
label .nlabel -text "Enter Name :" -bg lightblue
entry .entry_nlabel -width 40 -textvar Name(Name) -bg pink

label .label_add -text "Enter Address: " -bg lightblue
entry .entry_add -width 25 -textvar Address(Address) -bg pink
load

When run tk program, it automactically load the .save.setting into the field of the entry form so user can check or modify before proceeding to next step.

2)Here is my save/load proc
proc save { } {
global Name
global Address
set fid [open .save.file w]
puts $fid "Name $Name"
puts $fid "Address $Address"
close $fid
}
proce load { } {
global Name
global Address
if { [file exists .save.file] == 1 } {
set OpenID [open .save.file r ]
while { [gets $OpenID line] >= 0} {
switch [lindex $line 0] {
Name { set Name [lrange $line 1 end] }
Address { set Address [lrange $line 1 end] }

}
}
}
3) Content of file(.save.file)
Name Joe
Address 11 Nowhere

When I run this tk program, I got this error
Error in startup script: wrong # args: should be "load fileName ?packageName? ?interp?"
while executing
"load"

What am I doing wrong? Any insight is greatly appreciated.

Thanks in advance.
 
load" is a reserved token for the Tcl Library (DLL, SO) Load routine. Try something else.

_________________
Bob Rashkin
 
Thanks Bob for your reply. Well, it turns it does not matter what i called it load or loaddata. The reason for the error message is where the "load/loaddata" is placed. It needs to be end of the main program. It took me a while to firgure out and now it is working !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top