我想使用播放声音,但我得到:类型错误:'module'对象不可调用此错误


import turtle,random
import playsound
t = turtle.Turtle()
s = turtle.Screen()
t.speed(0)
colors = ["red", "blue", "yellow", "green","cyan","orange","brown","pink","purple"]
s.bgcolor("orange")
t.penup()
t.goto(-200, -10)
t.pendown()
def h():
    t.lt(90)
    t.forward(120)
    t.rt(90)
    t.forward(25)
    t.rt(90)
    t.forward(50)
    t.lt(90)
    t.forward(40)
    t.lt(90)
    t.forward(50)
    t.rt(90)
    t.forward(25)
    t.right(90)
    t.forward(120)
    t.rt(90)
    t.forward(25)
    t.rt(90)
    t.forward(50)
    t.left(90)
    t.forward(40)
    t.left(90)
    t.forward(50)
    t.right(90)
    t.forward(25)
def a():
    t.penup()
    t.goto(-75,-10)
    t.rt(110)
    t.pendown()
    t.forward(125)
    t.rt(70)
    t.forward(20)
    t.rt(70)
    t.fd(129)
    t.rt(110)
    t.fd(20)
    t.rt(70)
    t.forward(100)
    t.left(130)
    t.forward(113)
def p():
    t.penup()
    t.goto(-175,-130)
    t.pendown()
    t.rt(150)
    t.forward(100)
    t.rt(90)
    t.forward(20)
    t.rt(90)
    t.forward(60)
    t.left(90)
    t.penup()
    t.goto(-155, -90)
    t.pendown()
    t.circle(30,180)
    t.penup()
    t.goto(-175, -130)
    t.right(180)
    t.pendown()
    t.fd(20)
    t.left(90)
    t.fd(40)
    t.penup()
    t.goto(-145,-130)
    t.pendown()
    t.write("2",font=("Normal",30,"normal"))
def y():
    t.penup()
    t.goto(-30,-130)
    t.pendown()
    t.forward(50)
    t.lt(35)
    t.forward(50)
    t.penup()
    t.goto(-30,-130)
    t.pendown()
    t.rt(125)
    t.forward(20)
    t.lt(90)
    t.forward(50)
    t.rt(35)
    t.forward(50)
    t.lt(125)
    t.forward(15)
    t.lt(55)
    t.forward(40)
    t.penup()
    t.goto(-56,-40)
    t.pendown()
    t.rt(-125)
    t.forward(15)
    t.rt(55)
    t.forward(40)
    t.hideturtle()
def _22_():
    t.penup()
    t.goto(60,-80)
    t.write("22!",font=("Normal", 100, "normal"))
    t.goto(30,-180)
    t.write("BRO!",font=("Courier", 80, "italic"))
def sound():
    playsound(r"C:\Users\FreddyPycharmProjects\pythonProject\l.mp3")
h()
a()
p()
y()
sound()
_22_()
while True:
    s.bgcolor(random.choice(colors))
turtle.done()

C: 弗雷迪 PycharmProjects 用户pythonProject venv Scripts python.exe C:UsersFreddy PycharmProjects pythonProject main.py回溯(最近一次调用):文件"C:UsersFreddyPycharmProjectspythonProjectmain.py",第122行,在声音()文件"C:UsersFreddyPycharmProjectspythonProjectmain.py",第116行,声音playsound (r" C: 用户弗雷迪 PycharmProjects pythonProject l.mp3")TypeError: 'module' object is not callable

进程结束,退出代码1

那是因为你没有提到playsound和python认为它是一个def函数。当你导入playsound时,试着这样做:

from playsound import *

或做的事:

from playsound import playsound

否则,您还可以更改实际代码本身,并执行:

playsound.playsound(r"C:\Users\FreddyPycharmProjects\pythonProject\l.mp3")

希望这解决了你的问题!

相关内容

  • 没有找到相关文章

最新更新