Python - Making text files
<p>I seem to be having various problems with my code. Firstly I cannot split the text that the user inputs. </p>

<p>E.g. if they type <code>bob</code> for their name, <code>ha8 9qy</code> for their postcode and <code>17/03/10</code> for their date of birth, the program will return <code>"bobha8 9qy17/03/10"</code>. </p>

<p>How should I separate the input? Secondly i cannot find the text file I supposedly make. Lastly, is there a way to return the information to the new display window created by Tkinter?</p>

<pre><code>import tkinter as kt
name=input("Enter your name")
postcode=input("Enter your postcode")
dob=input("Enter your date of birth")

window=kt.Tk()
window.title("File")
window.geometry("300x150")
def submit():
    pythonfile = open("User details","w")
    pythonfile.write((name))
    pythonfile.write((postcode))
    pythonfile.write((dob))
    pythonfile = open(("User details"),"r")
    print (pythonfile.read())
    pythonfile.close()
Btn = kt.Button(window, text="Submit", command=submit)
Btn.pack()
</code></pre>

<p>You have to add the <code>.txt</code> afther the filename. Also be sure that the file is in the same folder of the <code>.py</code> file. Pay attention to caps and spaces.</p>

<p><code>pythonfile = open("User details.txt","w")</code></p>

<p>If this does'nt work, try adding <code>os.chdir(os.path.dirname(os.path.abspath(sys.argv[0])))</code> afther the import, for me it fixed the problem.</p>

<p>For the "spacing problem" try:</p>

<p><code>pythonfile.write(name, '\n', postcode, '\n', dob)</code></p>

<p>Also, when you create a alias for Tkinter use tk, and when you open a file try naming it file_it, or f_in, so it's more readable for other people ...
When naming files don't use spaces, it's just going to make everything harder, try naming it like this: <code>userDetails.txt</code> or <code>user_details.txt</code></p>

python tkinter