简体   繁体   English

AttributeError: 'function' object 没有属性 'read' — 我该如何修复?

[英]AttributeError: 'function' object has no attribute 'read' — HOW CAN I FIX?

My code:我的代码:

import simpleaudio as sa
import tkinter
from tkinter import *
from tkinter import filedialog
import wave

raiz = Tk()
raiz.geometry("200x300")

#function that plays song -is not playing eith a function in parameters, only with the path
def add_song():
    song = filedialog.askopenfilename(initialdir='Downloads/', title="Escolha uma musica", filetypes=(("wav files", "*.wav"), ))

my_menu = Menu(raiz)
raiz.config(menu=my_menu)

addmusica_menu = Menu(my_menu)
my_menu.add_cascade(label="Adicionar", menu=addmusica_menu)
addmusica_menu.add_command(label="Uma Música", command=add_song)

def play():
    wave_read = wave.open(add_song, 'rb')
    wave_obj = sa.WaveObject.from_wave_read(wave_read)
    wave_obj = sa.WaveObject.from_wave_file(add_song)
    play_obj = wave_obj.play()

def stop():
    play_obj.stop()

Rightframe = Frame(raiz)
Rightframe.pack(pady=1)

middleframe = Frame(Rightframe)
middleframe.pack(pady=5, padx=5)

play_img = PhotoImage(file='botoes/play.png')
playBt = Button(middleframe, image=play_img, borderwidth=0, command=play)
playBt.grid(row=10, column=2, padx=5)

parar_img = PhotoImage(file='botoes/parar.png')
pararBt = Button(middleframe, image=parar_img, borderwidth=0, command=stop)
pararBt.grid(row=10, column=0, padx=5)

raiz.mainloop()

error message:错误信息:

Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\tkinter\__init__.py", line 1883, in __call__
    return self.func(*args)
  File "playquefunciona.py", line 22, in play
    wave_read = wave.open(add_song, 'rb')
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\wave.py", line 510, in open
    return Wave_read(f)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\wave.py", line 164, in __init__
    self.initfp(f)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\wave.py", line 129, in initfp
    self._file = Chunk(file, bigendian = 0)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\chunk.py", line 61, in __init__
    self.chunkname = file.read(4)
AttributeError: 'function' object has no attribute 'read'
 wave_read = wave.open(add_song, 'rb')

in this line you are not calling the function add_song, and also in the function you are not returning anything在这一行中,您没有调用 function add_song,并且在 function 中,您没有返回任何内容

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AttributeError: 'function' object 没有属性 'split'。 我该如何解决? - AttributeError: 'function' object has no attribute 'split'. How I can fix it? 我该如何修复,AttributeError: 'NoneType' 对象没有属性 'send' - How can I fix, AttributeError: 'NoneType' object has no attribute 'send' 我该如何解决这个问题:AttributeError: 'NoneType' object has no attribute 'strip - How can i fix this :AttributeError: 'NoneType' object has no attribute 'strip AttributeError: 'int' 对象没有属性 'get' 我该如何修复它 - AttributeError: 'int' object has no attribute 'get' how can i fix it 如何修复错误 AttributeError: 'function' object has no attribute 'str' - How can I fix the error AttributeError: 'function' object has no attribute 'str' 如何修复“AttributeError: 'JpegImageFile' 对象没有属性 'read'? - How to fix "AttributeError: 'JpegImageFile' object has no attribute 'read'? 我收到一条错误消息,指出 AttributeError: 'str' object has no attribute 'read',我不知道如何修复它 - I'm getting an error that says AttributeError: 'str' object has no attribute 'read' and i do not know how to fix it 如何修复AttributeError:当我尝试替换csv读取中的某些文本时,“列表”对象没有属性“替换” - How to fix AttributeError: 'list' object has no attribute 'replace' when I try to replace some text in a csv read 如何修复 AttributeError: 'module' 对象没有属性 'function'? - How to fix AttributeError: 'module' object has no attribute 'function'? 如何修复“AttributeError:'function'对象没有属性'rcParams'” - How to fix “AttributeError: 'function' object has no attribute 'rcParams'”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM