I am making a game on python and tkinter, and I would like to save the highscores of the game. I have an entry which takes the name of the player and assign it to a global (Name1) and a global (Score1) in which the score is saved.
The thing is that I need a file that stores the best 10 highscores, obviously showing them from the biggest score to the lowest.
My question is: How do I make that?
How can I save the Name and the Score to the file? How can I save the scores with an order? (Including the name associated to the score)
I am really confused using the methods of .readline() and .write() and .seek() and all of those.
EDIT:
I need something like this:
The globals are Name1, Which lets say is "John" And Score1, Which at the end of the game will have an int object.
So after a few games, John achieved 3000 on the score, and then 3500, and then 2000.
The highscores file should look like:
John 3500
John 3000
John 2000
And if Mike comes out and play and achieve a 3200 score, the file should look like this:
John 3500
Mike 3200
John 3000
John 2000
The max amount of players on the highscore must be ten. So if there are already ten Highscores saved, and a bigger one comes out, the lowest score must be although ignored or deleted. (I need the file because I need to do the display on a Tkinter window)
PD: Excuse my weird English! Thank you!