【发布时间】:2018-03-17 22:11:27
【问题描述】:
我尝试为我的学校项目制作 mp3 混音器程序。我以为我们可以通过混合两首歌找到新歌
我在打球方面遇到了麻烦。每当我点击它时,就会发生错误
import sys,os
from PyQt5.QtWidgets import QWidget,QApplication,QPushButton,QVBoxLayout,QFileDialog,QHBoxLayout
from pygame import mixer
class Window(QWidget):
def __init__(self):
super().__init__()
self.init_ui()
def init_ui(self):
self.song1 = QPushButton("song1")
self.song2 = QPushButton("song2")
self.play_it = QPushButton("Play")
h_box = QHBoxLayout()
h_box.addWidget(self.song1)
h_box.addWidget(self.song2)
h_box.addWidget(self.play_it)
v_box = QVBoxLayout()
v_box.addLayout(h_box)
self.setLayout(v_box)
self.setWindowTitle("Song Mixer 1.0")
self.song1.clicked.connect(self.song1_open)
self.play_it.clicked.connect(self.play_the_songs)
self.show()
def song2_open(self):
file_name = QFileDialog.getOpenFileName(self,"Open",os.getenv("HOME"))
self.data2 = file_name[0]
def song1_open(self):
file_name = QFileDialog.getOpenFileName(self,"Open",os.getenv("HOME"))
self.data1 = file_name[0]
def play_the_songs(self):
mixer.init()
s1 =mixer.Sound(self.data1)
s2 =mixer.Sound(self.data2)
s1.play()
app = QApplication(sys.argv)
pencere = Window()
sys.exit(app.exec_())
感谢您的帮助!
【问题讨论】:
-
错误是秘密吗?如果没有,为什么不将其复制并粘贴到问题中?
-
@PatrickArtner 它没有像 Windows 错误那样响应
-
对于这些情况,像这样封装你的代码:
Try: your code Except Exception as e: print(e)(sn-p 2 at stackoverflow.com/questions/18982610/…) 它会打印你失败的地方。
标签: python python-3.x pygame pyqt5