The Wayback Machine - https://web.archive.org/web/20241127062646/https://www.geeksforgeeks.org/python-create-simple-animation-for-console-based-application/
Open In App

Python | Create simple animation for console-based application

Last Updated : 17 Apr, 2019
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

As we know Python is a scripting language, and can be easily used to automate simple tasks. In this article, we will learn how to create a simple console-based animation, which can be used while developing a console based project as a utility.

We will try to replicate the loading animation as shown below:

We will be using following modules –

sys module
os module
time module


 
Below is the Python implementation:




# importing the necessary packages
import time
import sys
import os
  
# Function for implementing the loading animation
def load_animation():
  
    # String to be displayed when the application is loading
    load_str = "starting your console application..."
    ls_len = len(load_str)
  
  
    # String for creating the rotating line
    animation = "|/-\\"
    anicount = 0
      
    # used to keep the track of
    # the duration of animation
    counttime = 0        
      
    # pointer for travelling the loading string
    i = 0                     
  
    while (counttime != 100):
          
        # used to change the animation speed
        # smaller the value, faster will be the animation
        time.sleep(0.075) 
                              
        # converting the string to list
        # as string is immutable
        load_str_list = list(load_str) 
          
        # x->obtaining the ASCII code
        x = ord(load_str_list[i])
          
        # y->for storing altered ASCII code
        y = 0                             
  
        # if the character is "." or " ", keep it unaltered
        # switch uppercase to lowercase and vice-versa 
        if x != 32 and x != 46:             
            if x>90:
                y = x-32
            else:
                y = x + 32
            load_str_list[i]= chr(y)
          
        # for storing the resultant string
        res =''             
        for j in range(ls_len):
            res = res + load_str_list[j]
              
        # displaying the resultant string
        sys.stdout.write("\r"+res + animation[anicount])
        sys.stdout.flush()
  
        # Assigning loading string
        # to the resultant string
        load_str = res
  
          
        anicount = (anicount + 1)% 4
        i =(i + 1)% ls_len
        counttime = counttime + 1
      
    # for windows OS
    if os.name =="nt":
        os.system("cls")
          
    # for linux / Mac OS
    else:
        os.system("clear")
  
# Driver program
if __name__ == '__main__': 
    load_animation()
  
    # Your desired code continues from here 
    # s = input("Enter your name: ")
    s ="David"
    sys.stdout.write("Hello "+str(s)+"\n")


Output:



Similar Reads

Building a Simple Application using KivyMD in Python
KivyMD is an extension of the Kivy framework. KivyMD is a collection of Material Design widgets for use with Kivy, a GUI framework for making mobile applications. It is similar to the Kivy framework but provides a more attractive GUI. In this article, we will see how to make a simple application in KivyMD using Screen, Label, TextFieldInput, and Bu
3 min read
Simple Chatbot application using Python, GoogleAPIKey
Google-GenerativeAI is Google AI Python SDK. It uses Gemini to build AI-powered features. In this article, we will see how to create a Simple Chatbot application using Python GoogleAPIKey. What is Google-GenerativeAI?Google-GenerativeAI is nothing but Google AI Python SDK. It enables to use of Gemini to build AI-powered features and applications. T
4 min read
Simple chat Application using Websockets with FastAPI
In this article, we'll delve into the concept of WebSockets and their role in facilitating bidirectional communication between clients and servers. Subsequently, we'll embark on the journey of building a real-time multi-client chat application. This application will empower numerous users to connect to the server via the WebSocket protocol, fosteri
6 min read
Flask - (Creating first simple application)
Building a webpage using python.There are many modules or frameworks which allow building your webpage using python like a bottle, Django, Flask, etc. But the real popular ones are Flask and Django. Django is easy to use as compared to Flask but Flask provides you with the versatility to program with.To understand what Flask is you have to understa
6 min read
Build an Application to Search Installed Application using Python
In this article, we are going to write python scripts to search for an installed application on Windows and bind it with the GUI application. We are using winapps modules for managing installed applications on Windows. Prerequisite - Tkinter in Python To install the module, run this command in your terminal: pip install winapps Below is what the GU
6 min read
Class Based vs Function Based Views - Which One is Better to Use in Django?
Django...We all know the popularity of this python framework all over the world. This framework has made life easier for developers. It has become easier for developers to build a full-fledged web application in Django. If you're an experienced Django developer then surely you might have been aware of the flow of the project. How things run in the
7 min read
Create a Simple Two Player Game using Turtle in Python
Prerequisites: Turtle Programming in Python TurtleMove game is basically a luck-based game. In this game two-players (Red & Blue), using their own turtle (object) play the game. How to play The game is played in the predefined grid having some boundaries. Both players move the turtle for a unit distance.Now both players flip the coin:if HEAD, t
4 min read
How to create a simple drawing board in Processing with Python Mode?
Processing is a programming language, and a development environment. It is an open-source software to create visual arts, graphics and animation using programming. It supports around 8 different modes, and in this article, we will be using Python Mode. In this article, we are going to create a simple drawing board using Processing with Python Mode.
3 min read
How to Create a Simple Messagebox in Python
Python has the capability to create GUI applications using libraries like tkinter and PyQt5. These libraries provide easy-to-use methods for creating various GUI elements, including messageboxes. In this article, we will explore both this approaches to create a simple messagebox in Python. Create A Simple Messagebox In PythonBelow are the possible
2 min read
Create simple Blockchain using Python
Blockchain is a time-stamped decentralized series of fixed records that contains data of any size is controlled by a large network of computers that are scattered around the globe and not owned by a single organization. Every block is secured and connected with each other using hashing technology which protects it from being tampered by an unauthor
8 min read
Taking input from console in Python
What is Console in Python? Console (also called Shell) is basically a command line interpreter that takes input from the user i.e one command at a time and interprets it. If it is error free then it runs the command and gives required output otherwise shows the error message. A Python Console looks like this. Here we write a command and to execute
2 min read
Blackjack console game using Python
Blackjack is a popular two-player card game that is played with a deck of standard playing cards around the world in casinos. The main criteria for winning this game are chance and strategy. The challenge of this game is to get as close to 21 points as possible without exceeding them. That is why it is also known as Twenty-One. In this article, we
6 min read
Create a Simple Sentiment Analysis WebApp using Streamlit
In this article, we will see how we can create a simple Sentiment Analysis webApp using with the help of Streamlit Module in Python. Required Modules: For this, we will need Three Modules. StreamlitTextBlobStreamlit_extras (optional). The module Streamlit_extras is optional because it will be used to add some extra features which will not affect th
4 min read
How to create a simple CGI script?
In this article, we will explore how to create a simple CGI (Common Gateway Interface) script on a Windows machine but before that, we need some basic ideas about these technologies ( CGI Script, HTTP, Web Server ).CGI Script: A CGI script is a program that runs on a web server and generates dynamic web content. It's often used for processing web f
2 min read
Create a Sideshow application in Python
In this article, we will create a slideshow application i.e we can see the next image without changing it manually or by clicking. Modules Required:Tkinter: The tkinter package (“Tk interface”) is the standard Python interface to the Tk GUI toolkit.Pillow: The Python Imaging Library adds image processing capabilities to your Python interpreter. Thi
2 min read
Create And Deploy A Stock Price Web Application using Python and Streamlit
In this article, we are going to see how to create and deploy a stock price web application. To create an amazing Web Application that deals with Data Science, we have a perfect platform to carry out this task. Streamlit and Python package builds and shares the data application in the fastest way possible. Streamlit is open source anyone can contri
4 min read
Create First GUI Application using Python-Tkinter
We are now stepping into making applications with graphical elements, we will learn how to make cool apps and focus more on its GUI(Graphical User Interface) using Tkinter. What is Tkinter?Tkinter is a Python Package for creating GUI applications. Python has a lot of GUI frameworks, but Tkinter is the only framework that’s built into the Python sta
12 min read
How to Use Twint OSINT Tool on Google Cloud Console ?
TWINT is an advanced Twitter scraping tool written in Python that allows for scraping Tweets from Twitter profiles without using Twitter's API. Twint utilizes Twitter's search operators to let you scrape Tweets from specific users, scrape Tweets relating to certain topics, hashtags, and trends, or sort out sensitive information from tweets like e-m
3 min read
Batch Script - Device Console
A batch script is a text file that includes various sequential commands. It is used to evaluate repetition routines in Windows, OS/2, and DOS operating systems and is used in network and system administration. A batch file refers to a file that stores command in a serial order. The library has been modified by Windows which can be used in Batch Scr
2 min read
How to zoom in and zoom out terminal console in linux
Linux is a Debian-based Operating system used by many professionals and other people for various purposes. Mainly Linux is used for Penetration testing and Vulnerability assessment. Windows systems often interact with GUI (graphical user interface) but in Linux, we use a terminal console more to interact with the system and to do things normally. I
7 min read
How to Use ‘Tmux Terminal’ to Access Multiple Terminals Inside a Single Console
tmux, or Terminal Multiplexer is a command-line tool for managing multiple terminal sessions in one window. It's beneficial for developers and system administrators, offering features like splitting the terminal into panes, creating sessions with windows and panes, customization, scripting, and remote access. Users can organize tasks efficiently, c
4 min read
Hide the console of an .exe file created with PyInstaller in Tkinter
PyInstaller is used with Tkinter to package the Python file into a stand-alone executable file in .exe format. The .exe file is a single file application or software which can be run on a Windows platform. This exe file contains all dependencies, and assets used in the Python file which helps both the nontechnical and technical users of the applica
3 min read
What is Terminal, Console, Shell and Kernel?
Understanding the terms terminal, console, shell, and kernel is crucial for anyone working with computers or learning about operating systems. These concepts are key components of how we interact with our devices and software. The terminal is a text-based interface used to interact with the computer, while the console is often referred to as the ph
5 min read
Python | Animation in Kivy using .kv file
Kivy is a platform independent GUI tool in Python. As it can be run on Android, IOS, Linux, and Windows, etc. It is basically used to develop the Android application, but it does not mean that it can not be used on Desktops applications. Animation: Animation and AnimationTransition are used to animate Widget properties. You must specify at least a
3 min read
Matplotlib.animation.FuncAnimation class in Python
Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack. matplotlib.animation.FuncAnimation The matplotlib.animation.FuncAnimation class is used to make animation by repeatedly calling the same f
4 min read
Creating a radar sweep animation using arcade in Python
The Radar Sweep are used for displays of single level sweeps of radar data, and their display appears in the Main Display window. With the help of arcade module of Python, it is possible to perform a radar sweep animation. Before starting, it is highly recommended to revise concepts of arcade library. To perform a radar sweep animation, follow the
3 min read
Python | Animation in Kivy
Kivy is a platform independent GUI tool in Python. As it can be run on Android, IOS, Linux and Windows, etc. It is basically used to develop the Android application, but it does not mean that it can not be used on Desktops applications. ?? Kivy Tutorial - Learn Kivy with Examples.Animation: Animation and AnimationTransition are used to animate Widg
2 min read
3D Modeling & Animation App Using Python
In recent times, Python has become widely recognized as a potent language for a variety of uses beyond the traditional realm of software development. One such domain is 3D modeling and animation, where Python's flexibility and user-friendly nature can be exploited to develop strong applications. This article will delve into the process of construct
9 min read
Using Timedelta and Period to create DateTime based indexes in Pandas
Real life data often consists of date and time-based records. From weather data to measuring some other metrics in big organizations they often rely on associating the observed data with some timestamp for evaluating the performance over time. We have already discussed how to manipulate date and time in pandas, now let's see the concepts of Timesta
3 min read
Create View - Function based Views Django
Create View refers to a view (logic) to create an instance of a table in the database. It is just like taking an input from a user and storing it in a specified table. Django provides extra-ordinary support for Create Views but let's check how it is done manually through a function-based view. This article revolves around Create View which involves
3 min read
Practice Tags :
three90RightbarBannerImg