user interface - Create a text document in python with whats in the variable as the name -
i trying create questionnaire in python using tkinter. far can:
1) utilize radio buttons, check boxes, spin box , entry form.
2) display these results in text box using variables each answer:
textbox.delete(0.0, end) textbox.insert(end, name) textbox.insert(end, "\n") textbox.insert(end, "age: ")
and on...
what need save these text document. because questionnaire want save file individually, name of person completing it. unfortunately wont allow me open word file while using variable. (the variable using called "name")
the error appears is:
file "d:\questionaire\module1.py", line 72, in button newfile = open(name) ioerror: [errno 2] no such file or directory: 'james'
(james word in variable @ time)
newfile = open(name) newfile.write("line one\n") newfile.write("line two\n")
is there way create text file variable, each time word file created doesn't replace 1 created before?
i have tried explaining best could, questions if doesn't create sense.
thank much :)
you using open
function incorrectly, write file, need open "w"
write mode.
try using
newfile = open(name, "w") newfile.write("line one\n") newfile.write("line two\n") newfile.close()
or improve still
with open(name, "w") name_file: name_file.write("line one\n") name_file.write("line two\n")
however, quite possible 2 people have same name, , so, values overwritten if open file in write mode everytime. so, right selection open file in append
mode:
with open(name, "a") name_file: name_file.write("line one\n") name_file.write("line two\n")
python user-interface tkinter text-files
No comments:
Post a Comment