2

Is there anyway I can make an application in which a button made in Glade can be clicked to play a custom re-definable sound?

1 Answer 1

2

You would need to connect the 'activate' signal of the button to a handler function that then calls a library to play a sound. For the sound playing part you can use any of the modules listed here

In glade select the button then choose signals and enter a name for the function handler: Glade-SignalHandler

Then in your python code for the window, create the function (on_iconbutton_activate in my example). Here's an example that just makes a system call to ring a bell:

import os
....otherstuff...

def on_iconbutton_activate(self,widget,data=None):
    os.system("/usr/bin/canberra-gtk-play --id='bell'")

EDIT: To make the sound redefinable, you'll need to pull the choice from somewhere. Just use a variable to store the choice (a filename for some module or id for canberra-gtk-play), you can store the variable in something like self.sound and reference it in the function (since you passed self to it), or update the variable from some widget when the button is clicked.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .