0

My idea was to insert a line of slow-moving text into a set of printed text after the printed text had finished printing out.

So for example:

@@@@@@@@@@@@@@
@  SlowText  @
@@@@@@@@@@@@@@

The border would be printed out immediately and then the SlowText would appear after a short period, writing out slowly.

I've tried a couple of different slow-moving text snippets to perform the actual writing. like:

def print_slow(txt):
    for x in txt:                    
        print(x, end='', flush=True) 
        sleep(0.1)

and

def insertedtext():
    text = " E..n..j..o..y..."
    for character in text:
        sys.stdout.write(character)
        sys.stdout.flush()
        time.sleep(0.05)

I've tried using '#'+ words + '#' , tried throwing another print("words") in there. Heck, I even attemped at making it a variable but since I am quite new to Python I just can seem to figure it out or google it correctly enough to find it on my own. Any/all help appricated.

martineau
  • 119,623
  • 25
  • 170
  • 301
062904
  • 1
  • 2
    If the border gets printed first, you need something like `ncurses` to reposition the text cursor. – Jongware Apr 24 '20 at 19:55

1 Answers1

0

I think this is what your looking for :

from time import sleep

def make_box (character, width) :
    print (character * (width + 4))
    print (character + ' ' * (width + 2) + character)
    print (character * (width + 4))

def print_slow (character, text):
    print ('\033[2A' + character, end = ' ')
    for x in text:                    
        print (x, end='', flush=True) 
        sleep (0.1)
    print ()

box_character = '@'
text = 'This is a test'
make_box (box_character, len (text))
print_slow (box_character, text)

The line print ('\033[2A... moves the cursor up two lines.

bashBedlam
  • 1,402
  • 1
  • 7
  • 11
  • That make_box is pretty neato i will admit, but sadly when i try your code it outputs this :( ``` @@@@@@@@@@@@@@@@@@ @ @ @@@@@@@@@@@@@@@@@@ ←[2A@ This is a test ``` – 062904 Apr 24 '20 at 20:13