I have made a full game of tycoon but what i need for the game is that i want to save the player configure the money and the stores that 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 try my idea which the player could load from the txt file and save the txt file btw the txt file is a code that lead to the program and make changes.
>Solution :
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