Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+4 votes

For my final project I am trying to display the score the whole time you are playing, but I am having a problem. The score updates, but it flashes. I think it is because of where my .undraw() is but not sure. Here is the function:

while keepPlaying:
    scoreText = Text(Point(700, 50), f"Score: {score}")
    scoreText.setTextColor('purple')
    scoreText.setSize(15)
    scoreText.draw(window)
    (some code for the game between here)
     scoreText.undraw()
asked in CSC201 Spring 2021 by (1 point)

1 Answer

+2 votes

I recommend just creating the Text object ONCE, above the while loop,

scoreText = ...
scoreText.setTextColor(...)

and then inside of the WHILE loop, you can just call the .setText(...) method to change the text that is displaying within the object, rather than undrawing/drawing it every time.

scoreText.setText(f"Score: {score}")

This should eliminate any flicker/blinking.

answered by (5.7k points)
+1

Thank you!!!

...