30-04-2021, 02:15 PM
Código:
import matplotlib
import numpy as np
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
from tkinter import *
import tkinter as tk
import tkinter.filedialog
from scipy.io import wavfile
#from pyo import *
import time
import sys
#import sounddevice as sd
class window:
def __init__(self, window):
self.window = window
"""
IGRESO DE AUDIOS
"""
self.button = Button(window, text="Audio canal 1", bg = 'black', fg = 'White', command = self.plot_1)
self.button.place(x = 100, y = 20)
self.button2 = Button (window, text="Audio canal 1", bg = 'black', fg = 'White', command = self.plot_2)
self.button2.place(x = 400, y = 20)
self.button3 = Button (window, text="Audio canal 1", bg = 'black', fg = 'White', command = self.plot_3)
self.button3.place(x = 700, y = 20)
self.button4 = Button (window, text="Audio canal 1", bg = 'black', fg = 'White', command = self.plot_4)
self.button4.place(x = 1030, y = 20)
self.button5 = Button (window, text="Audio canal 1", bg = 'black', fg = 'White', command = self.plot_5)
self.button5.place(x = 1300, y = 20)
"""
BOTÓN DE VOLUMEN
"""
self.buttonvol1 = Button(window, text = "ajustar el volumen canal 1", bg = 'black', fg = 'white', command = self.volume_1)
self.buttonvol1.place(x = 60, y = 500)
self.buttonvol2 = Button(window, text = "ajustar el volumen canal 1", bg = 'black', fg = 'white', command = self.volume_2)
self.buttonvol2.place(x = 360, y = 500)
self.buttonvol3 = Button(window, text = "ajustar el volumen canal 1", bg = 'black', fg = 'white', command = self.volume_3)
self.buttonvol3.place(x = 660, y = 500)
self.buttonvol4 = Button(window, text = "ajustar el volumen canal 1", bg = 'black', fg = 'white', command = self.volume_4)
self.buttonvol4.place(x = 960, y = 500)
self.buttonvol5 = Button(window, text = "ajustar el volumen canal 1", bg = 'black', fg = 'white', command = self.volume_5)
self.buttonvol5.place(x = 1260, y = 500)
"""
Slider
"""
""
self.slider = Scale(window, bg = 'gray42', fg = 'white', to = 0, from_ = 100, resolution = 1, length = 200, orient = 'vertical')
self.slider.set(50)
self.place(x = 130, y = 270)
self.slider2 = Scale(window, bg = 'gray42', fg = 'white', to = 0, from_ = 100, resolution = 1, length = 200, orient = 'vertical')
self.slider2.set(50)
self.place(x = 430, y = 270)
self.slider3 = Scale(window, bg = 'gray42', fg = 'white', to = 0, from_ = 100, resolution = 1, length = 200, orient = 'vertical')
self.slider3.set(50)
self.place(x = 730, y = 270)
self.slider4 = Scale(window, bg = 'gray42', fg = 'white', to = 0, from_ = 100, resolution = 1, length = 200, orient = 'vertical')
self.slider4.set(50)
self.place(x = 1030, y = 270)
self.slider5 = Scale(window, bg = 'gray42', fg = 'white', to = 0, from_ = 100, resolution = 1, length = 200, orient = 'vertical')
self.slider5.set(50)
self.place(x = 1300, y = 270)
""
"""
FUNCIONES DE PLOT
"""
"""
CANAL 1
"""
def plot_1 (self):
fm, shk = wavfile.read("D://Descargas//Dynoro_in_my_mind.wav ")
dur1 = len(shk)/fm
gra = Figure(figsize = (4,2), constrained_layout = NONE)
gra.set.facecolor('DodgerBlue2')
a1 = gra.add_subplot(111)
a1.set_facecolor('DodgerBlue2')
time1 = np.linspace(0, dur1, num = len(shk))
a1.plot(time, shk, color = 'dark orange')
a1.set_title("Grafica canal 1", fontisize = 15)
a1.set_ylabel('Amplitud',fontisize = 12)
a1.set_xlabel('Tiempo [s]',fontisize = 12)
canvas = FigureCanvasTkAgg(gra, master = self.window)
canvas.get_tk_widget().place(x = 20, y = 90 )
def volume_1(self):
fm1,shk1 = wavefile.read("")
factor1 = self.slider.get()
song1a = shk1*(factor1/100)
song1b = np.int16(song1a)
"""
CANAL 2
"""
def plot_2 (self):
fm2, shk = wavfile.read("D://Descargas//Dynoro_in_my_mind.wav ")
dur2 = len(shk)/fm2
gra2 = Figure(figsize = (4,2), constrained_layout = NONE)
gra2.set.facecolor('DodgerBlue2')
a2 = gra2.add_subplot(111)
a2.set_facecolor('DodgerBlue2')
time2 = np.linspace(0, dur2, num = len(shk))
a2.plot(time2, shk, color = 'dark orange')
a2.set_title("Grafica canal 1", fontisize = 15)
a2.set_ylabel('Amplitud',fontisize = 12)
a2.set_xlabel('Tiempo [s]',fontisize = 12)
canvas = FigureCanvasTkAgg(gra2, master = self.window)
canvas.get_tk_widget().place(x = 20, y = 90 )
def volume_2(self):
fm2,shk2 = wavefile.read()
factor2 = self.slider2.get()
song2a = shk*(factor2/100)
song2b = np.int16(song2a)
"""
CANAL 3
"""
def plot_3 (self):
fm3, shk = wavfile.read("")
dur3 = len(shk)/fm3
gra3 = Figure(figsize = (4,2), constrained_layout = NONE)
gra3.set.facecolor('DodgerBlue2')
a3 = gra3.add_subplot(111)
a3.set_facecolor('DodgerBlue2')
time3 = np.linspace(0, dur3, num = len(shk))
a3.plot(time, shk, color = 'dark orange')
a3.set_title("Grafica canal 1", fontisize = 15)
a3.set_ylabel('Amplitud',fontisize = 12)
a3.set_xlabel('Tiempo [s]',fontisize = 12)
canvas = FigureCanvasTkAgg(gra3, master = self.window)
canvas.get_tk_widget().place(x = 20, y = 90 )
def volume_3(self):
fm3,shk3 = wavefile.read()
factor3 = self.slider3.get()
song3a = shk3*(factor3/100)
song3b = np.int16(song3a)
"""
CANAL 4
"""
def plot_4 (self):
fm4, shk = wavfile.read("")
dur4 = len(shk)/fm4
gra4 = Figure(figsize = (4,2), constrained_layout = NONE)
gra4.set.facecolor('DodgerBlue2')
a4 = gra4.add_subplot(111)
a4.set_facecolor('DodgerBlue2')
time4 = np.linspace(0, dur4, num = len(shk))
a4.plot(time4, shk, color = 'dark orange')
a4.set_title("Grafica canal 1", fontisize = 15)
a4.set_ylabel('Amplitud',fontisize = 12)
a4.set_xlabel('Tiempo [s]',fontisize = 12)
canvas = FigureCanvasTkAgg(gra4, master = self.window)
canvas.get_tk_widget().place(x = 20, y = 90 )
def volume_4(self):
fm4,shk4 = wavefile.read()
factor4 = self.slider4.get()
song4a = shk4*(factor4/100)
song4b = np.int16(song4a)
"""
CANAL 5
"""
def plot_5 (self):
fm5, shk = wavfile.read("")
dur5 = len(shk)/fm5
gra5 = Figure(figsize = (4,2), constrained_layout = NONE)
gra5.set.facecolor('DodgerBlue2')
a5 = gra5.add_subplot(111)
a5.set_facecolor('DodgerBlue2')
time5 = np.linspace(0, dur5, num = len(shk))
a5.plot(time5, shk, color = 'dark orange')
a5.set_title("Grafica canal 1", fontisize = 15)
a5.set_ylabel('Amplitud',fontisize = 12)
a5.set_xlabel('Tiempo [s]',fontisize = 12)
canvas = FigureCanvasTkAgg(gra5, master = self.window)
canvas.get_tk_widget().place(x = 20, y = 90 )
def volume_5(self):
fm5,shk5 = wavefile.read()
factor5 = self.slider5.get()
song5a = shk5*(factor5/100)
song5b = np.int16(song5a)
"""
Abrir Archivo
"""
"""
def callback(): # Canal 1
global name
name = askopenfilename()
samplerate, data = wavfile.read(''+name+'')
points = len(data)
maximo= max(data[0&points])
data = data/20000.0
timeArray = np.arrange(0, points, 1)
timeArray = timeArray/float(samplerate)
win2(timeArray.data.points)
print( "/nLa ruta del archivo es:"+name)
"""
def main():
root = tk.Tk()
app = window(root)
app.mainloop()
if __name__ == '__main__':
main()
la línea 73 : 'window' object has no attribute 'place'
la línea 255 : AttributeError: 'window' object has no attribute 'mainloop'
agradezco su ayuda muchachos, gracias.