[Tutor] A volume control (:

Larry llwyble at cox.net
Fri Nov 21 01:51:27 EST 2003


Well, I have been working on this and got this far but I think I screwed up
Because I can't figure out how to set the initial volume on the slider instead of
it going back to 0 (zero) everytime I start it.  I wanted to use:

Current_vol = mixer.get(ossaudiodev.SOUND_MIXER_VOLUME)

To get the current volume of the mixer. But I didn't consider this until 
I got this far and I don't think my slider code is going to allow an initial setting
of the slider. Or is it?  Arg...

Any hints or tips or pointers? 
Thanks

I gotta go to bed, it's 12:45 in the morning and I gotta get up and go to
work in 5 hours.   (:
Maybe things will be clearer in the A.M.       or not!   (:

Also thanks to everyone who has helped so far. 

Larry

_________________________________________________________________________________
#!/usr/local/bin/python


from Tkinter import *

import ossaudiodev
mixer = ossaudiodev.openmixer()

class VOLUME(Frame):
    def print_value(self, val):
        ival = int(val)
        a = (ival,ival)
        mixer.set(ossaudiodev.SOUND_MIXER_VOLUME, a)

    def createWidgets(self):
        self.slider = Scale(self, from_=0, to=100,
                            orient=HORIZONTAL,
                            length="3i",
                            command=self.print_value)

        self.QUIT = Button(self, text='QUIT', foreground='red', command=self.quit)

        self.slider.pack(side=LEFT)
        self.QUIT.pack(side=LEFT, fill=BOTH)

    def __init__(self, master=None):
        Frame.__init__(self, master)
        Pack.config(self)
        self.createWidgets()

test = VOLUME()
test.mainloop()








More information about the Tutor mailing list