How to clear screen | Sololearn: Learn to code for FREE!

+8

How to clear screen

I'm writing a program to simulate a page to create an account and log in. (check out on: https://code.sololearn.com/cfqgqjMeE1sV/#py) I've searched for a function/statement to clear the screen everytime I change from "create account page" to "log in page", but I didn't find anything that worked. I tried: def clear(): os.system('cls') but I failed. So, as a temporary solution, I printed 100 new lines to have the same effect. I wonder, is there any other way to do this? Thanks in advance. PS: check out my other codes if you like ;)

3/31/2017 4:52:56 PM

LayB

9 Answers

New Answer

+8

@David Najafi I tried this: >>> import os >>> clear = lambda: os.system('cls') >>> clear() but a cmd prompt poped up and vanished instantly, but nothing changed on my program I also tried on linux, replacing 'cls' by 'clear' but didn't work either

+7

@David Najafi I tried on IDLE and pycharm but didn't worked

+6

@David Najafi I work with Windows and I used import. Still, didn't work

+2

The playground of SoloLearn does not support some functions. Like OS functions. Or httpservice functions, for php and other languages. And c++ in SOLOLEARN does not support some header files like Windows.h

+2

For Windows DON'T FORGET THE IMPORT import os os.system("cls") For OS X, you can use subprocess module and call 'cls' from shell: import subprocess as sp sp.call('cls',shell=True) To prevent '0' from showing on top of the window, replace the 2nd line with: tmp = sp.call('cls',shell=True) For linux, you must replace cls command with clear tmp = sp.call('clear',shell=True)

+2

Call it like this >>> import os >>> clear = lambda: os.system('cls') >>> clear()

+2

try assigning os.system to a variable so it doesn't return 0

+1

If you are writing your code on Android, which is based on Linux, then use the following - import os , then os.system("clear")

0

import os os.system('cls')