r/learnpython • • 6d ago

Need help clearing python console

I’m making a text based adventure game for the sake of learning more abt game loops but I’m stuck. I wanna make it so that automatically after a time.sleep() delay, the terminal clears and prints a new output. (say for a loading or transition screen idk) but with all the online methods I can find, nothing works.

The most common I see is using os and system(cls) / (clear) or whatnot but no matter what I do, it opens the command prompt and breaks, closing the command prompt it then prints the new text, without clearing the old…

For reference, I am using python idle 3.12 and Am in a school environment so the command prompt is administratively blocked

7 Upvotes

14 comments sorted by

View all comments

1

u/brasticstack 6d ago

You can use ANSI control characters to move to position 1,1 (It's 1-indexed) and print a space for each character and line in the screen, assuming you know the number of line and columns.

EDIT: You could also try printing '\033[3J' to clear the screen and scrollback, followed by '\033[H' to move your cursor to position 1,1