Skip to content
Sign upLog in
← Back to Community

Python Question

Profile icon
GeoneveStudios

Python Question

I have a question. In Python how do you make a loading animation.

Answered by 19wintersp [earned 5 cycles]
View Answer
Voters
Profile icon
RAP
Profile icon
ch1ck3n
Profile icon
GeoneveStudios
Comments
hotnewtop
Profile icon
19wintersp

What kind do you want? If you want to overwrite the current line, you can use a carriage return ("\r"). The main thing is having different frames of the animation, and cycling between them:

from time import sleep frames = [".", "..", "..."] # or maybe frames = ["/", "-", "\\", "|"] for i in range(0, 10): for frame in frames: print("\r" + frame, end="") sleep(0.2)
Profile icon
GeoneveStudios

@19wintersp
Thank you; but can it be more simple than that. Because I'm probably going to forget that.

Profile icon
19wintersp

@DashStudios

but can it be more simple than that

I'm really don't understand your point here. This is a bare-bones implementation of doing this.

Profile icon
GeoneveStudios

@19wintersp
nevermind I get it now

Profile icon
RYANTADIPARTHI

Solution

Here is how.

import time import os for x in range(10): print('/') time.sleep(.5) os.system('clear') print('-') time.sleep(.5) os.system('clear') print('\\') time.sleep(.5) os.system('clear')

like that.
That should work

Profile icon
GeoneveStudios

@RYANTADIPARTHI
Thats helpful

Profile icon
RYANTADIPARTHI

@DashStudios
no problem.

Profile icon
GeoneveStudios

@RYANTADIPARTHI
I'm waiting for 2 more answers to see which is the best

Profile icon
RYANTADIPARTHI

@DashStudios
ok

Profile icon
awesomecds7

if you want to make one with graphics, you have to use a moudule called tkinter

import tkinter as tk from tkinter import * from tkinter.ttk import * ####LOADING SCREEN#### import time for i in range(3): ws = Tk() def step(): for i in range(37): ws.update_idletasks() pb1['value'] += random.choice(adl) time.sleep(random.choice(wl)) pb1.destroy() ws.destroy() pb1 = Progressbar(ws, orient=HORIZONTAL, length=379, mode='determinate') pb1.pack(expand=True) step()
Profile icon
awesomecds7

@awesomecds7
Please note that this will loop 3 times.

Profile icon
GeoneveStudios

@19wintersp
post was the most helpful

Profile icon
SenatorBinks

@FloCal35
has a good tutorial here

Profile icon
Mozyyoo

I would use Pygame for that, but that's more so game graphics. If you are looking for that though, i recommend this tutorial: https://www.youtube.com/watch?v=UdsNBIzsmlI

Profile icon
GeoneveStudios

Does anyone know how to make a loading animation.