关于pyQt的按键连接问题及next()de 使用
def record_generator(fileName, recordBtn):global RECORDING
p = pyaudio.PyAudio()
stream = p.open(format=FORMAT,
channels=CHANNELS, rate=RATE,
input=True, frames_per_buffer=CHUNK)
while 1:
recordBtn.setText(u'开始录制')
yield
recordBtn.setText(u'停止录制')
RECORDING = True
t = threading.Thread(target=record_thread, args=(fileName, stream, p))
t.setDaemon(True)
t.start()
yield
RECORDING = False
app = QApplication(sys.argv)
mainWindow = QWidget()
mainWindow.resize(250,300)
mainWindow.setWindowTitle(u'录制界面')
layout = QVBoxLayout()
btn = QPushButton()
g = record_generator('output.wav', btn)
next(g)
btn.pressed.connect(next(g))
这个代码不是自己写的我想在上面做修改 原代码版本是pyqt4,我安装的
原本next函数的调用方法为g.next(),btn.pressed.connect(g
.next)
但是next修改以后调用方法为next(g),我不清楚btn.pressed.connect()中该如何写
写作btn.pressed.connect(next(g))报错:recording
Traceback (most recent call last):
File "wav5.py", line 50, in <module>
btn.pressed.connect(next(g))
TypeError: argument 1 has unexpected type 'NoneType'