I have built a game that logs and saves the users score, using pickle, to a text file. When their lives are used up, they enter their name and their name and score are saved to a text file. Currently, if the "High Scores" section is selected on the main menu the high scores are simply printed in the python shell (or CMD if they're using that). I would like to create a separate window for just displaying the high scores. The window would simply display the scores and would refresh every time it is opened.
Currently I have the code to load the pickled file and create a new window. If I enter static text it works fine but when I try to display the text file contents I get the following error:
Traceback (most recent call last): File "C:\LearnArabic\Program\Test1.py", line 22, in textsurface = myfont.render(high_scores, False, (0, 0, 0)) TypeError: text must be a unicode or bytes
Here is my code:
import pygame
from operator import itemgetter
import pickle
pygame.font.init()
high_scores = []
with open("C:\\LearnArabic\\HighScores\\HighScores.txt", 'rb') as f:
high_scores = pickle.load(f)
#Background color
background_color = (255,255,255)
(width, height) = (400, 500)
HighScoreScreen = pygame.display.set_mode((width, height))
pygame.display.set_caption('High Scores')
HighScoreScreen.fill(background_color)
#Displaying text on window
myfont = pygame.font.SysFont('Comic Sans MS', 30)
textsurface = myfont.render(high_scores, False, (0, 0, 0))
HighScoreScreen.blit(textsurface,(0,0))
pygame.display.flip()
running = True
while running:
for event in pygame.event.get():
if event.type ==pygame.QUIT:
running = False
Is there a different function from render that would allow me to display the results in a tabular form?
I'm relatively new to programming and am using python 3. Thanks for the help!