Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


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 EdinsonC   Members   -  Reputation: 256

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.


“Everybody is a genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid.” -Albert Einstein

Sponsor:

#2 WeberM   Members   -  Reputation: 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   -  Reputation: 508

Like
2Likes
Like

Posted 19 March 2014 - 08:08 PM

Another option is to say something like this:

print '\n' * 100


#4 EdinsonC   Members   -  Reputation: 256

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


“Everybody is a genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid.” -Albert Einstein

#5 Oralordos   Members   -  Reputation: 508

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   Crossbones+   -  Reputation: 13888

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.



PARTNERS