0

MY Tycoon game image

I have made a full game of tycoon, but what I need for the game is that I want to save the player money and the stores that are still running with this code. I use PyCharm and Python 3.9.

Also I use Tkinter GUI for it and have been 5 project so please help <'_'>

I have tried my idea which is the player could load from the txt file and save the txt file. Btw, the txt file is a code that leads to the program and makes changes.

2 Answers 2

0

You can use:

text = 'Your text'
with open('save.txt', 'w') as file:
    file.write(text)

This will cause the 'save.txt' file to be completely overwritten with 'Your text'.

If you want to read the text that is written in the file you would have to use:

with open('save.txt', 'r') as file:
    text = file.read()

You could implement it like this:

save_file = '<your save file path>'
with open(save_file, 'r') as file:
    text = file.read()

# game code

text = '<str that will be saved inside of save_file>'
with open(save_file, 'w') as file:
    file.write(text)

You can find other solutions to this problem here: How to create a new text file using Python

Sign up to request clarification or add additional context in comments.

2 Comments

I ussually use this kind of code def insert_data(self): if self.file_path: name = self.name_entry.get() age = self.age_entry.get() email = self.email_entry.get() if name and age and email: with open(self.file_path, 'a', newline='') as csvfile: fieldnames = ['Name', 'Age', 'Email'] writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writerow({'Name': name, 'Age': age, 'Email': email}) messagebox.showinfo("Success", "Data inserted successfully!") I made it by my
Maybe in your case is better to save inside a JSON file
0

use input function and take details from the user

1 Comment

But what if in applications?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.