2

I'm trying to use .get() to access entry from my Scale but the volume doesn't change when I move slider. I'm using pygame mixer too btw.

Relevant code;

def change_vol():
    sounds.music.set_volume(vol.get())
#########################################
def play_music():
    load_music()
    sounds.music.play()
    pass
##########################
def load_music():
    sounds.music.load("fakeplastic.wav")


vol = Scale(
    sound_box,
    from_ = 0,
    to = 1,
    orient = HORIZONTAL ,
    resolution = .1,
)
vol.grid(row = 3, column = 1)

If you'd like me to post any other snippets please ask, thanks.

finefoot
  • 9,914
  • 7
  • 59
  • 102
Damhan Richardson
  • 419
  • 1
  • 5
  • 16

1 Answers1

4

It looks like you forgot to assign the Scale's command option to change_vol so that the function is called each time you adjust the scale:

vol = Scale(
    sound_box,
    from_ = 0,
    to = 1,
    orient = HORIZONTAL ,
    resolution = .1,
    ####################
    command=change_vol
    ####################
)

You will also need to redefine change_vol to accept the event object that will be sent to it every time you move the scale:

def change_vol(_=None):
    sounds.music.set_volume(vol.get())

I did _=None to make it clear that you are not using the argument inside the function.

  • Adding that gives the error; Exception in Tkinter callback Traceback (most recent call last): File "/usr/lib/python3.4/tkinter/__init__.py", line 1490, in __call__ return self.func(*args) TypeError: change_vol() takes 0 positional arguments but 1 was given – Damhan Richardson Nov 21 '14 at 00:08
  • @DamhanRichardson - Ah, an event object is being sent to `change_vol`. See my edit. –  Nov 21 '14 at 00:10
  • You're the best! couldnt find this anywhere online. – Damhan Richardson Nov 21 '14 at 00:12