gpt4 book ai didi

Python模块wx不播放音频声音

转载 作者:行者123 更新时间:2023-12-03 02:08:57 30 4
gpt4 key购买 nike

在我的程序中,我尝试随机播放一些声音。但问题是,我听不到他们的声音。我没有收到错误或类似的东西,我只是听不到声音。谢谢您的帮助。对不起,如果我的英语不好。这也是我的代码:

import Tkinter as tk
import random
import wx

class SampleApp(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)

self.state("zoomed")

container= tk.Frame(self)
container.config()
container.pack(side="top", fill="both", expand=True)
container.grid_rowconfigure(0, weight=2)
container.grid_columnconfigure(0, weight=1)

self.frames={}
for F in (fenster, fensta):
frame= F(container, self)
self.frames[F]=frame
frame.grid(row=0, column=0, sticky="nsew")
frame.pack_propagate(0)

self.show_frame(fenster)

def show_frame(self, c):
frame=self.frames[c]
frame.tkraise()

class fenster(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)

button=tk.Button(self, text="Start",
command=lambda: controller.show_frame(fensta))
button.pack()

class fensta(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
def ok():
def do_a():
def __init__(self, parent):
wx.Frame.__init__(self, parent)
self.test = wx.Sound('ja.wav')
self.test.Play(wx.SOUND_SYNC)

print("a")

def do_b():
def __init__(self, parent):
wx.Frame.__init__(self, parent)
self.testa = wx.Sound('nein.wav')
self.testa.Play(wx.SOUND_SYNC)

print("b")

a=random.randint(1,2)

if a==1:
do_a()
elif a==2:
do_b()

button=tk.Button(self, text="press", command=ok)
button.pack()

if __name__== "__main__":
app=SampleApp()
app.mainloop()

最佳答案

你不能混合使用 wxPython 和 Tkinter。

关于Python模块wx不播放音频声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25811633/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com