I have managed to make it work like the following: That might not be the most effective solution but for now I make it work. Thank you so much guys for your hints. It works like I wanted it to.
def highest_score(self):
try:
with open("score.csv", "r") as file:
data = file.readlines()[0]
highscore = int(data)
if self.score > highscore:
with open("score.csv", 'w') as file:
file.write(str(self.score))
self.text_score.write(f"Game over!\nYour highest score is: {self.score}", align="center", font=("Arial", 20, "normal"))
else:
with open("score.csv", 'w') as file:
file.write(str(highscore))
self.text_score.write(f"Game over!\nYour highest score is: {highscore}", align="center", font=("Arial", 20, "normal"))
except FileNotFoundError:
with open("score.csv", 'w') as file:
file.write(str(self.score))
self.text_score.write(f"Score: {self.score}", align="center", font=("Arial", 20, 'normal'))