+ 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 ;)

31st Mar 2017, 4:52 PM
LayB
LayB - avatar
9 Respuestas
+ 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
1st Apr 2017, 12:53 PM
LayB
LayB - avatar
+ 7
@David Najafi I tried on IDLE and pycharm but didn't worked
31st Mar 2017, 5:36 PM
LayB
LayB - avatar
+ 6
@David Najafi I work with Windows and I used import. Still, didn't work
31st Mar 2017, 5:43 PM
LayB
LayB - avatar
+ 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
31st Mar 2017, 5:34 PM
David Najafi
David Najafi - avatar
+ 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)
31st Mar 2017, 5:41 PM
David Najafi
David Najafi - avatar
+ 2
Call it like this >>> import os >>> clear = lambda: os.system('cls') >>> clear()
31st Mar 2017, 5:46 PM
David Najafi
David Najafi - avatar
+ 2
try assigning os.system to a variable so it doesn't return 0
1st Apr 2017, 2:55 PM
David Najafi
David Najafi - avatar
+ 1
If you are writing your code on Android, which is based on Linux, then use the following - import os , then os.system("clear")
29th Jul 2017, 8:45 PM
Rick Zalman
0
import os os.system('cls')
2nd Apr 2017, 12:08 AM
Michael Carson
Michael Carson - avatar