Python Forum
[Tkinter] Messagebox with playsound - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: [Tkinter] Messagebox with playsound (/thread-26744.html)



Messagebox with playsound - khandelwalbhanu - May-12-2020

I am trying to play sound(recorded sound of message in message box) with message box.

playsound('myrecord.wav')
messagebox.askquestion('Information',info)

But in this case sound is playing first and after completion of this task, message box appears.

messagebox.askquestion('Information',info)
playsound('myrecord.wav')

And in this case message box appears first and then sound plays after disappearing of message box.

But i want to play recorded sound with message box at the same time.
How can i achieve it?


RE: Messagebox with playsound - chesschaser - May-12-2020

Try this in Python 3:

from tkinter import messagebox
import winsound

winsound.Beep(2000, 300)
messagebox.showinfo("Beeping box", "This is a beeping messagebox!", icon = "info", parent = None)



RE: Messagebox with playsound - deanhystad - May-12-2020

Have you tried using a thread?
import threading

threading.Thread(target=playsound, args=('myrecord.wav',)).start()
messagebox.askquestion('Information',info)



RE: Messagebox with playsound - chesschaser - May-12-2020

Try this. You'll need to install pygame though.

from pygame import mixer
from tkinter import messagebox

mixer.init()

recording = mixer.Sound("myrecording.wav")

recording.play()
messagebox.showinfo("Try this", "it'll work", icon = "info", parent = None)
This'll defintely work try this first


RE: Messagebox with playsound - chesschaser - May-15-2020

Did my solution work?


RE: Messagebox with playsound - khandelwalbhanu - May-16-2020

Thank you. It works. Smile


RE: Messagebox with playsound - chesschaser - May-16-2020

:) I'll be happy to give you more help if needewd!