When I use tkinter with playsound it frezes untill the sound is played. I have tried using block = False but then it dosnt play the sound at all!
This is part of my code:
from tkinter import *
from tkinter import ttk
from playsound import playsound
class GameMaker:
def __init__(self,root=None):
self.sounds={}
def AddSound(self,name,directory,overide=False,times=0,TimesOveride=0):
if times != 0:
name = name + str(times)
if TimesOveride != 0:
if times >= 10:
return None
else:
if times >= TimesOveride:
return None
try:
self.sounds[name]
if overide == True:
self.sounds[name]=directory
else:
AddSound(name,directory,times=times+1)
except:
self.sounds[name]=directory
def PlaySound(self,sound):
playsound(self.sounds[sound],block=False)
def MapAll(self,command):
keys = list("qwertyuiopasdfghjklzxcvbnm")
for key in keys:
self.Bind(key,command)
print(key)
game.sounds['Tap-1'] = "C:\Users\Not Shownin\Desktop\GameMaker\v0.1\Tap-1.mp3"
game.sounds['Tap-2'] = "C:\Users\Not Shownin\Desktop\GameMaker\v0.1\Tap-2.mp3"
from random import randint
def Tap(event):
print("tap")
if randint(1,2) == 1:
game.PlaySound("Tap-1")
else:
game.PlaySound("Tap-1")
I know it is a lot but there is lots more.
A break down of my code is that it just adds the direcotory to the sounds dictionary so i can play it later.