How to update a '.txt' file with filedialog Python (3.x)?

Discussion in 'HTML en webdesign' started by Nolan1, Dec 8, 2014.

  1. Nolan1

    Nolan1 New Member

    Joined:
    Nov 18, 2014
    Messages:
    12
    Likes Received:
    1
    How would I be able to create a '.txt' file and store some information from an entry box and be able to update the '.txt' file?

    I understand that I would have to use:

    file = filedialog.asksaveasfile( mode = 'w', defaultextension = '.txt')

    and store the information form the Entrybox into the file:

    #the self.nameEntry had the input of 'zack'
    name = self.nameEntry.get()
    file.write(name)
    file.close()

    But when the program continues to run and I want to save the new information into the same .txt file, how would I be able to accomplish that without using filedialog.asksaveasfile() all over again? Would I use file = open(file) and then use the file.write()? Thank you for your help in advance.
     

Share This Page

Loading...