def button_open_camera_click(self): if self.timer_camera.isActive() == False: flag = self.cap.open(self.CAM_NUM) if flag == False: msg = QtWidgets.QMessageBox.warning(self, u"Warning", u"请检测相机与电脑是否连接正确", buttons=QtWidgets.QMessageBox.Ok, defaultButton=QtWidgets.QMessageBox.Ok) # if msg==QtGui.QMessageBox.Cancel: # pass else: self.timer_camera.start(30) self.button_open_camera.setText(u'关闭相机') else: self.timer_camera.stop() self.cap.release() self.label_show_camera.clear() self.button_open_camera.setText(u'打开相机')