Jump to content

  • Log In with Google      Sign In   
  • Create Account

How to clear screen in python


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   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   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   Members   

892
Like
2Likes
Like

Posted 19 March 2014 - 08:08 PM

Another option is to say something like this:

print '\n' * 100


#4   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   Members   

892
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   Members   

20266
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.