0

I'm wanting to play a sound while some text is being printed out, but how do I go about doing this at the same time? Here is what I have to work with.

import winsound as win
import sys
import time


text = "I like Pizza!"
for letter in text:
    sys.stdout.write(letter)
    sys.stdout.flush()
    time.sleep(0.5)


gametheme = "Place where the sound is stored"

win.PlaySound(gametheme, win.SND_FILENAME)

1 Answers1

0

(Copied) Threading in python is used to run multiple threads (tasks, function calls) at the same time. Note that this does not mean that they are executed on different CPUs. Python threads will NOT make your program faster if it already uses 100 % CPU time. In that case, you probably want to look into parallel programming.

Programs run line by line, so it is difficult to run it at the same time. It is only possible with threads. A thread is another program, linked to another program, which run at the same time, side-by-side. I have never used them before, but I could tell you some websites.

docs.python.org

stackoverflow :)

Oqhax
  • 419
  • 1
  • 4
  • 16
  • I have seen threading before but being a beginner at Python it seemed complicated. But I need a solution to this so I'll look up a tutorial for threading. Thanks :) – wolfspiderzx Aug 22 '17 at 22:47