1

I want to make typewritter effect with delay between each character.

However my problem is when I put a variable between the text it doesn't work.

import sys,time

message = "What's your name?\n"

def typewritter(message):
    for char in message:
        sys.stdout.write(char)
        sys.stdout.flush()
        if char != ("\n"):
            time.sleep(0.1)
        else:
            time.sleep(1)

typewritter(message)
    
name = str(input(''))

namehello = ("Hello ",name, " I'm .........")

typewritter(namehello)

the first part works but not the second, anyone knows how?.

2 Answers 2

2

You defined namehello as tuple not string, keep namehello as string to make it work (using an f-string for example):

namehello = f"Hello {name} I'm ........."
Sign up to request clarification or add additional context in comments.

Comments

0

you can use "Textfx" library for add typing effects to your text.

first, install textfx library pip install textfx

then use typeeffect() for effect your text. sample code:

from textfx import typeeffect

typeeffect("Hello, world!", delay=0.1)

Hope this helps!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.