I am trying to write a program that plays the Morse code sound while showing the Morse code.
The problem that I have is sound plays before showing the Morse code in the program. The program has a UI based on tkinter:
for item in self.morse_code:
self.output_text_area.config(state="normal")
self.output_text_area.insert(END, item)
self.output_text_area.config(state="disable")
play_sound(self.morse_code)
I am using the playsound library and below is the the function in charge of playing the sound:
from playsound import playsound
def play_sound(morse_code: list):
print(morse_code)
for code in morse_code:
print(code)
for char in code:
if char == '-':
playsound('sound/morse_line.mp3')
elif char == '.':
playsound('sound/morse_dot.mp3')
elif char == '|':
continue
time.sleep(0.05)
time.sleep(1)
How can I get the program to show the Morse Code first , then play Morse Code sound? Currently, even though the code for updating the text_area
executes first, the sound plays first then after it is done it will show the Morse Code.