Jump to content

Image of the Day

Everything is fine. 

#screenshotsaturday #indiedev #gamedev https://t.co/98BAKUInyo
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net's newsletters to receive the latest updates and exclusive content.


Sign up now

How to clear screen in python

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
5 replies to this topic

#1 EdinsonC   Members   

269
Like
0Likes
Like

Posted 19 March 2014 - 03:36 PM

OKay, so i've been learning python for the last month and three weeks using the python IDLE, but it's become really annoying to see the games i make stack up all the text on top of each other. Is there any way that i can make it so that the screen is cleared and the game is updated and re-shown to the player? thanks.



#2 WeberM   Members   

111
Like
2Likes
Like

Posted 19 March 2014 - 07:19 PM

Try this:

import os
os.system('cls')

on windows or this on linux:

os.system('clear')

Good Luck!



#3 Oralordos   Members   

905
Like
2Likes
Like

Posted 19 March 2014 - 08:08 PM

Another option is to say something like this:

print '\n' * 100


#4 EdinsonC   Members   

269
Like
0Likes
Like

Posted 19 March 2014 - 08:33 PM

Thank you weberM that worked perfectly, and Oralordos XD lmaoo yea i guess that could work too, but then you'd have a scrolling bar on the side which i wouldn't want there



#5 Oralordos   Members   

905
Like
0Likes
Like

Posted 19 March 2014 - 11:34 PM

To make your code more cross platform you can use sys.platform to find out what os you are running on.



#6 Álvaro   Members   

20680
Like
0Likes
Like

Posted 20 March 2014 - 08:00 AM

If your terminal supports ANSI escape codes, you can do this:

 

sys.stdout.write("\033[2J")





Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.