Ask coding questions

← Back to all posts
Prevent screen flickering/paint over screen

When I use a clear function (that I made so I can use in windows + linux), it flickers the screen, and is unbearable. Im wondering if there is a way to prevent the screen from flickering, or paint over the screen (stackoverflow told me to do this, but I dont know how.)

Answered by pyelias (2625) [earned 5 cycles]
View Answer
pyelias (2625)

Screen flickering happens when your program output gets split up and doesn't all arrive in your browser at the same time. To force it to be sent all at once, you can use code like this.


@pyelias going to look into it, but this seems like using an ansi escape code

pyelias (2625)

@TaylorLiang It is, does that cause any problems?


@pyelias not really, not really that portable, but Ill use it!

HarperframeInc (456)

When you clear, your adding a bunch of '\n' lines quickly. The computer can't do it instantly, so you have screen flickering. I'm sorry, but I don't think you can fix this.

However, if you want to at least slow the process down, you shouldn't use a while loop and clear at the same time. Slow it down by using time.sleep(seconds).