Jump to content

Clearing screen in python

Go to solution Solved by fizzlesticks,

 

11 minutes ago, Pythons said:

        sys.stderr.write(char)
        sys.stdout.flush()

You're writing to stderr but flushing stdout. stderr should only be used for errors.

 

Quote

import os

os.system('cls')

 

It doesn't work in IDLE, only python.exe

You can't clear the screen in IDLE. You can print a bunch of blank lines but that will look horrible, best option is to fix the other problem and run it outsite of an IDE.

Hello all,
I'm trying to create a text based game currently, although, I've run into a issue:
My code has a 'typewriter' effect by using the code below:


def txtdelay(text):
    for char in text:                  
        sleep(0.038)                  
        sys.stderr.write(char)
        sys.stdout.flush()

 

text("Example")


It doesn't work in python.exe, only in IDLE

I want to have my code refresh the screen after a while by using this:

 

import os

os.system('cls')

 

It doesn't work in IDLE, only python.exe

Any help would be appreciated!! :)

Link to comment
https://linustechtips.com/topic/739852-clearing-screen-in-python/
Share on other sites

Link to post
Share on other sites

 

11 minutes ago, Pythons said:

        sys.stderr.write(char)
        sys.stdout.flush()

You're writing to stderr but flushing stdout. stderr should only be used for errors.

 

Quote

import os

os.system('cls')

 

It doesn't work in IDLE, only python.exe

You can't clear the screen in IDLE. You can print a bunch of blank lines but that will look horrible, best option is to fix the other problem and run it outsite of an IDE.

1474412270.2748842

Link to post
Share on other sites

6 minutes ago, fizzlesticks said:

 

You're writing to stderr but flushing stdout. stderr should only be used for errors.

 

You can't clear the screen in IDLE. You can print a bunch of blank lines but that will look horrible, best option is to fix the other problem and run it outsite of an IDE.

Thanks a bunch! :)

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×