Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #80678 > unrolled thread

Synchronizing a sound with a widget change

Started by"ast" <nomail@invalid.com>
First post2014-11-13 11:50 +0100
Last post2014-11-13 11:15 -0500
Articles 7 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  Synchronizing a sound with a widget change "ast" <nomail@invalid.com> - 2014-11-13 11:50 +0100
    Re: Synchronizing a sound with a widget change "ast" <nomail@invalid.com> - 2014-11-13 11:56 +0100
      Re: Synchronizing a sound with a widget change "ast" <nomail@invalid.com> - 2014-11-13 12:06 +0100
        Re: Synchronizing a sound with a widget change Dave Angel <davea@davea.name> - 2014-11-13 06:42 -0500
          Re: Synchronizing a sound with a widget change "ast" <nomail@invalid.com> - 2014-11-13 14:25 +0100
    Re: Synchronizing a sound with a widget change "Yimr Zero" <yimr00@gmail.com> - 2014-11-13 22:34 +0800
    Re: Synchronizing a sound with a widget change Dave Angel <davea@davea.name> - 2014-11-13 11:15 -0500

#80678 — Synchronizing a sound with a widget change

From"ast" <nomail@invalid.com>
Date2014-11-13 11:50 +0100
SubjectSynchronizing a sound with a widget change
Message-ID<54648d03$0$1981$426a74cc@news.free.fr>
Hello, here is a small test code:

----------------
from tkinter import Tk, Frame
from winsound import Beep

root = Tk()

f = Frame(root, width=300, height=300)
f.pack()

f.config(bg='Yellow')
Beep(2000, 1000)
--------------

I intended to change the frame color to yellow (f.config(bg='Yellow'))
and at the same time to emit a sound (Beep(2000, 1000))

But I first have the sound and when the sound is over the window appears.

Is there a way to fix that ?

I have the idea to run an other thread to emit the sound, but I didn't try yet.
Is it the solution ?

Thanks

[toc] | [next] | [standalone]


#80679

From"ast" <nomail@invalid.com>
Date2014-11-13 11:56 +0100
Message-ID<54648e75$0$12771$426a74cc@news.free.fr>
In reply to#80678
"ast" <nomail@invalid.com> a écrit dans le message de news:54648d03$0$1981$426a74cc@news.free.fr...

>
> I have the idea to run an other thread to emit the sound, but I didn't try yet.
> Is it the solution ?
>

nope, still doesn't work !

-------------------------------------------
from tkinter import Tk, Frame
from winsound import Beep

def mybeep():
    Beep(2000, 1000)

root = Tk()

f = Frame(root, width=300, height=300)
f.pack()

f.config(bg='Yellow')
root.after(1, mybeep)
-------------------------------------------- 

[toc] | [prev] | [next] | [standalone]


#80680

From"ast" <nomail@invalid.com>
Date2014-11-13 12:06 +0100
Message-ID<546490c1$0$2890$426a74cc@news.free.fr>
In reply to#80679
"ast" <nomail@invalid.com> a écrit dans le message de news:54648e75$0$12771$426a74cc@news.free.fr...
>
> "ast" <nomail@invalid.com> a écrit dans le message de 
> news:54648d03$0$1981$426a74cc@news.free.fr...
>
>>
>> I have the idea to run an other thread to emit the sound, but I didn't try yet.
>> Is it the solution ?
>>
>
> nope, still doesn't work !
>

> root.after(1, mybeep)


with:

f = Frame(root, width=300, height=300)
f.pack()
f.config(bg='Yellow')
root.after(80, mybeep)

it works and with:

f = Frame(root, width=300, height=300)
f.pack()
f.config(bg='Yellow')
root.after(60, mybeep)

it doesn't work

I understand that Python takes times to create the root
window and to color the frame. It the sound arrives
before the end of the drawing, Python goes to the sound
emitting,and when finished it goes back to drawing.

This is annoying
I would like sometuhing stable if possible

thx

[toc] | [prev] | [next] | [standalone]


#80681

FromDave Angel <davea@davea.name>
Date2014-11-13 06:42 -0500
Message-ID<mailman.15773.1415878987.18130.python-list@python.org>
In reply to#80680
"ast" <nomail@invalid.com> Wrote in message:
> 
> "ast" <nomail@invalid.com> a écrit dans le message de news:54648e75$0$12771$426a74cc@news.free.fr...
>>
>> "ast" <nomail@invalid.com> a écrit dans le message de 
>> news:54648d03$0$1981$426a74cc@news.free.fr...
>>
>>>
>>> I have the idea to run an other thread to emit the sound, but I didn't try yet.
>>> Is it the solution ?
>>>
>>
>> nope, still doesn't work !
>>
> 
>> root.after(1, mybeep)
> 
> 
> with:
> 
> f = Frame(root, width=300, height=300)
> f.pack()
> f.config(bg='Yellow')
> root.after(80, mybeep)
> 
> it works and with:
> 
> f = Frame(root, width=300, height=300)
> f.pack()
> f.config(bg='Yellow')
> root.after(60, mybeep)
> 
> it doesn't work
> 
> I understand that Python takes times to create the root
> window and to color the frame. It the sound arrives
> before the end of the drawing, Python goes to the sound
> emitting,and when finished it goes back to drawing.
> 
> This is annoying
> I would like sometuhing stable if possible
> 

I don't use Windows, but from what I read,  winsound.Beep is a
 blocking call, and therefore must not be used in the main thread
 of a gui environment. 
Once the function is called, no events are
 processed. 


It seems like you need winsound.SND_ASYNC

-- 
DaveA

[toc] | [prev] | [next] | [standalone]


#80682

From"ast" <nomail@invalid.com>
Date2014-11-13 14:25 +0100
Message-ID<5464b162$0$5112$426a74cc@news.free.fr>
In reply to#80681
"Dave Angel" <davea@davea.name> a écrit dans le message de 
news:mailman.15773.1415878987.18130.python-list@python.org...

>
> I don't use Windows, but from what I read,  winsound.Beep is a
> blocking call, and therefore must not be used in the main thread
> of a gui environment.
> Once the function is called, no events are
> processed.
>
>
> It seems like you need winsound.SND_ASYNC
>

Yes, you are right.
I have to use winsound.PlaySound(sound, flags)
with flag = winsound.SND_ASYNC

thx 

[toc] | [prev] | [next] | [standalone]


#80687

From"Yimr Zero" <yimr00@gmail.com>
Date2014-11-13 22:34 +0800
Message-ID<mailman.15777.1415889291.18130.python-list@python.org>
In reply to#80678

[Multipart message — attachments visible in raw view] — view raw

Hi,

You may try to add the sleep(5) after the color change statement. You could adjust the sleep time to let the color change and beep synchroize.

Thanks.



Yimr Zero
 
From: ast
Date: 2014-11-13 18:50
To: python-list
Subject: Synchronizing a sound with a widget change
Hello, here is a small test code:
 
----------------
from tkinter import Tk, Frame
from winsound import Beep
 
root = Tk()
 
f = Frame(root, width=300, height=300)
f.pack()
 
f.config(bg='Yellow')
Beep(2000, 1000)
--------------
 
I intended to change the frame color to yellow (f.config(bg='Yellow'))
and at the same time to emit a sound (Beep(2000, 1000))
 
But I first have the sound and when the sound is over the window appears.
 
Is there a way to fix that ?
 
I have the idea to run an other thread to emit the sound, but I didn't try yet.
Is it the solution ?
 
Thanks
 
 
 

[toc] | [prev] | [next] | [standalone]


#80691

FromDave Angel <davea@davea.name>
Date2014-11-13 11:15 -0500
Message-ID<mailman.15781.1415895324.18130.python-list@python.org>
In reply to#80678
"Yimr Zero" <yimr00@gmail.com> Wrote in message:
> body { line-height: 1.5; }blockquote { margin-top: 0px; margin-bottom: 0px; margin-left: 0.5em; }body { font-size: 10.5pt; font-family: 'Segoe UI'; color: rgb(0, 0, 0); line-height: 1.5; }
> Hi,
> You may try to add the sleep(5) after the color change statement. You could adjust the sleep time to let the color change and beep synchroize.
> Thanks.
> 

But sleep () doesn't have a non blocking version. You'd have to
 put it in another thread to get it out of the way.


-- 
DaveA

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web