[Tutor] A volume control (:

Larry llwyble at cox.net
Fri Nov 21 20:59:43 EST 2003


On Fri, 21 Nov 2003 20:45:49 +0100
Michael Lange <klappnase at freenet.de> wrote:

> On Fri, 21 Nov 2003 00:51:27 -0600
> Larry <llwyble at cox.net> wrote:
> 
> > 
> > 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...
> > 
> > 
> Hi Larry,
> 
> I think you should use a Tkinter.DoubleVar for the volume settings
> which you can bind to the Scale widget(in case the volume is a float
> value, I don't know about ossaudiodev, if it is an integer of course
> you should use a Tkinter.IntVar()).
> If you set the value of this variable to the current volume before the
> scale is created I think it should work:
> 
> > #!/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,
>      			         variable=self.Current_vol)


This didn't set the current volume.  I'm not really sure what it does.
The variable word is a global name. It's coming after the call to print.
And even if I put it before the call to print, it doesn't change the setting
of the  scale on startup. It still starts at zero.  I'm not completely sure
what to do with 'variable'.   (:

Where can I read about 'variable' and the relationship with 'IntVar()'

I'm pretty green at this and I don't quite grasp what's going on here.

Thanks



> >         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)


> 	  #get the current volume setting:

> 	  self.Current_vol = IntVar()
> 	  self.Current_vol.set(mixer.get(ossaudiodev.SOUND_MIXER_VOLUME ))
>         self.createWidgets()

> > 
> > test = VOLUME()
> > test.mainloop()



> Like I said, I don't know what mixer.get() returns, (I haven't even
> ossaudiodev installed), but I think this should do the trick to set
> the initial volume.
> 
> Cheers
> 
> Michael
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 


-- 
--------------------------------------------
[Thy] kiss is comfortless as frozen water to a starved snake.
-William Shakespeare, Troilus and Cressida



More information about the Tutor mailing list