[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pygame] Anyone tried Pygame + Tkinter?



> Anyway, it looks to me that the sound is cancelled, not only paused, 
> because if I put sleep () in the idle callback it does not play anything 
> neither - whereas when I put sleep() immediately after play(), it works

ahh, after fiddling with this for awhile, and dreaming up all sorts of 
strange ideas, the solution whacked me across the face. let's take a 
quick look at your button handler..

     def play (self, ev):
         sound = mixer.Sound (file)
         sound.play()

now, the magic question is.. what do you expect the lifetime of the 
"sound" variable to be? if you guessed, "sound will be destroyed when 
this function returns" then you are correct!

heh, if this doesn't make sense quite yet, change the play function to this.

     def play(self, ev):
         self.sound = mixer.Sound(file)
         self.sound.play()

now the lifetime of your "sound" variable will be tied to the lifetime 
of the interface class. thus it will be around long enough for the sound 
to play :]

what's even more impressive is you got no segfault! hooray for pygame 
and sdl_mixer

____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org