Posts I've Made
14 December 2013 - 09:59 PMI figured mine out as well!
I had not put parentheses in order to make stop a method. Also, I needed to place the shutdown method inside the sound_panel module and include the protocol method inside there too.
14 December 2013 - 10:44 AMNot working for me! I get:
Exception in Tkinter callback Traceback (most recent call last): File "C:\Python34\lib\tkinter\__init__.py", line 1475, in __call__ return self.func(*args) File "C:\Users\Charlie\Documents\Python\djMix4.py", line 15, in shutdown track.stop() NameError: name 'track' is not defined
Here's my code:
from tkinter import * import pygame.mixer def create_gui(app, mixer, sound_file): def track_toggle(): if track_playing.get() == 1: track.play(loops = -1) else: track.stop def change_volume(v): track.set_volume(volume.get()) track = mixer.Sound(sound_file) track_playing = IntVar() track_button = Checkbutton(app, variable = track_playing, command = track_toggle, text = sound_file) track_button.pack(side = 'left') volume = DoubleVar() volume.set(track.get_volume()) volume_scale = Scale(variable = volume, from_ = 0.0, to = 1.0, resolution = 0.1, command = change_volume, label = 'Volume', orient = 'horizontal') volume_scale.pack(side = 'right')
from tkinter import * import pygame.mixer from sound_panel import * app = Tk() app.title("Head First DJ") mixer = pygame.mixer mixer.init() create_gui(app, mixer, "50459_M_RED_Nephlimizer.wav") create_gui(app, mixer, "49119_M_RED_HardBouncer.wav") def shutdown(): track.stop() app.destroy() app.protocol("WM_DELETE_WINDOW", shutdown) app.mainloop()
- I GOT IT!!
- I HAD NOT PLACED THE IMPORT lines on top
- I GOT IT!!
11 December 2013 - 08:35 AMWhat is the error that you're getting from this code?
11 December 2013 - 08:34 AMIf it works, cool. But that is a lot more typing just to get the same effect :/
But its great to learn new ways to achieve things in programming, that way you know you've really learned something
11 December 2013 - 08:32 AMI am running Py 3.4 under W7. Did you get it working yet?