'Animation delete and replace full output string block

I am creating a dice animation on python and for it to work, the different ascii figures have to replace the previous outputted one.

I know how to replace a string line, in this example the "hello" word will disappear:

print("hello", end="")
print("\r", end="")

But for my code to work, I have to replace a whole str block, here is my attempt:

from time import sleep


def animation():
    print(r''' 
       -------- 
      | O    O |
      | O    O |
      | O    O |
       --------
    ''',end="""""")
    sleep(0.7)
    print("\r",end="""""")

    print(r'''
        ((
           ----------  ))
          / O    O  /
         / O    O  /
        / O    O  /
        --------- 
    ((
    ''',end="""""")
    sleep(0.7)
    print("\r",end="""""")
    print(r''' 
       ---------  ))
      |  O O O  |
      |         |
      |  O O O  |
       ---------
     ((  
    ''',end="""""")
    sleep(0.7)
    print("\r",end="""""")

    print(r'''
     ((            
         ---------   ))
         \  O   O  \
          \  O   O  \
           \  O   O  \
             ---------  ))
    ''',end="""""")
    sleep(0.7)
    print("\r",end="""""")

animation()

But in the output I get all figures separately and don't get them to replace the previous one. Does anyone have a solution?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source