How can you avoid generating line breaks while using print in python3.4?

1

I have the following function

 def reproducir(texto):
    pygame.mixer.music.load(TECLADO) 

    for letra in str(texto):
       pygame.mixer.music.play()
       print(letra, end="")
       time.sleep(0.05)
       sys.stdout.flush()

 pygame.mixer.music.stop() 

As you can see the function prints letter by letter the text with a background sound.

If I press enter while the letters are printed, it generates a line break and distorts the msj.

If you press any other letter, it prints on the screen and distorts the msj.

How can I prevent this from happening?

    
asked by jose.gb89 04.10.2016 в 20:16
source

1 answer

1

I have managed to use curses to get what I was looking for, however it seems to me that there must be another simpler way.

As for sys.stdout.flush() , it did not work for me as I expected, since at the end when I entered a value, the keys that were previously pressed were saved.

I got sys.stdin.flush() and it did not give me the expected results, but the following worked for me:

termios.tcflush(sys.stdin, termios.TCIOFLUSH)
    
answered by 05.10.2016 в 19:52