-2

So I have this code and immediately after the code is completed I want to clear the screen and run another code automatically, please how do I do this?

def load():
    n("Loading")
    for load in range(1,4):
        n(".")
        time.sleep(1)


load()
Tobias Wilfert
  • 919
  • 3
  • 14
  • 26
Curtis Crentsil
  • 459
  • 6
  • 20
  • What do you mean with the screen? Do you mean the terminal? – Tobias Wilfert Mar 15 '19 at 13:39
  • 1
    Possible duplicate of [Any way to clear python's IDLE window?](https://stackoverflow.com/questions/1432480/any-way-to-clear-pythons-idle-window) – Tobias Wilfert Mar 15 '19 at 13:54
  • all the stuff there doesn't work all it does is print 100 new lines or doesn't work at all, does it work in python 3.7 – Curtis Crentsil Mar 15 '19 at 13:58
  • 1
    @Curris How about you then write a better question where you explain that you are working with python 3.7 and want the clear the idle window instead of the screen? – Tobias Wilfert Mar 15 '19 at 14:57
  • `for x in range(1, 4): n('.') time.sleep(1) print('\n' * 100)` just moves down 100 line or you can change how many you want (tested in python3.7) – n1tk Mar 15 '19 at 16:08
  • There is no environment-independent way to clear a window unless you use a cross-platform GUI framework such as tkinter, which wraps tcl/tk. To load and read another file, use `with open('somefile.py') as f\n exec(f.read())`. – Terry Jan Reedy Mar 15 '19 at 23:42

3 Answers3

2

To clear the output of the script use following on Windows:

import os
os.system('cls')

Or this for Linux/MacOS

import os
os.system('clear')
alberand
  • 632
  • 5
  • 13
0

Something like this will work

import os
os.system('cls')
Ugnes
  • 709
  • 1
  • 9
  • 23
0

Take a look at this: Introduction to python

import os

# Show a simple message.
print("I like climbing mountains.")

# Clear the screen.
os.system('clear')

In the above example, you will see no "I like climbing mountains." because as soon as the message is displayed the terminal will be cleared.

Note: The command to clear the terminal screen is different on Windows. The command os.system('cls') should work.

Tobias Wilfert
  • 919
  • 3
  • 14
  • 26