Python 3 Script to Clear Screen in Application Using Sleep Method in Time Module Full Project For Beginners

You are currently viewing Python 3 Script to Clear Screen in Application Using Sleep Method in Time Module Full Project For Beginners

 

 

Welcome folks today in this blog post we will be clearing screen in application using sleep method in time module in python. All the full source code of the application is shown below.

 

 

 

 

Get Started

 

 

 

In order to get started you need to make an app.py file and copy paste the following code

 

 

app.py

 

 

# import only system from os
from os import system, name

# import sleep to show output for some time period
from time import sleep

# define our clear function
def clear():

    # for windows
    if name == 'nt':
        _ = system('cls')

    # for mac and linux(here, os.name is 'posix')
    else:
        _ = system('clear')

# print out some text
print('hello geeks\n'*10)

# sleep for 2 seconds after printing output
sleep(2)

# now call function we defined above
clear()

 

Now if you execute the python script by typing the below command as shown below

 

 

python app.py

 

 

 

Leave a Reply