Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

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

online printing

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1 Alejandro

Alejandro

    CC Lurker

  • New Member
  • Pip
  • 9 posts

Posted 08 December 2014 - 12:02 PM

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.



#2 BlackRabbit

BlackRabbit

    CodeCall Legend

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3871 posts

Posted 10 December 2014 - 11:52 AM

You just need a flag to tell you it's not the first time.






Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download