您可以在 windows 中同时执行另一项任务时播放声音吗?

Can you play sound in windows while doing another task simultaneously?

有没有办法在玩winsound.PlaySound("some sound", FLAGS)的时候也换一个photolabel?我一直在尝试,无论我把播放声音放在哪里,它总是在更改我的照片标签之前播放声音。

我的代码:

def thriller(self):
    winsound.PlaySound("thriller.wav", winsound.SND_NODEFAULT)
    img5 = ImageTk.PhotoImage(Image.open('thriller.jpg'))
    self.photoLabel.configure(image = img5)
    self.photoLabel.image = img5
    self.original_board()

def original_board(self):
    from PIL import Image, ImageTk
    self.image = Image.open("board.jpg")
    self.photo = ImageTk.PhotoImage(self.image)
    self.photoLabel.after(5000, lambda:    self.photoLabel.configure(image=self.photo))

是的,你可以。您必须异步播放声音。标志 winsound.SND_ASYNC 应该可以完成工作。如果这没有帮助,您可以在新线程(或 python 更好的新进程)中生成 winsound 函数,以便在图像更改的同时播放。

祝你好运!