调用其他脚本时Python系统崩溃

调用其他脚本时Python系统崩溃,python,Python,我正在做一个有两个按钮的Python系统,当我调用主窗口挂起的其中一个函数时,如何修复它?虽然我可以正常运行另一个脚本,但主窗口崩溃,我需要关闭它。 主窗口代码: from PyQt5 import QtWidgets, uic import sys import os class Ui(QtWidgets.QMainWindow): def __init__(self): super(Ui, self).__init__() uic.loadUi('tela_principal

我正在做一个有两个按钮的Python系统,当我调用主窗口挂起的其中一个函数时,如何修复它?虽然我可以正常运行另一个脚本,但主窗口崩溃,我需要关闭它。 主窗口代码:

from PyQt5 import QtWidgets, uic
import sys
import os
class Ui(QtWidgets.QMainWindow):
def __init__(self):
    super(Ui, self).__init__()
    uic.loadUi('tela_principal.ui', self)
    self.button = self.findChild(QtWidgets.QPushButton, 'btnMonitoramento')
    self.button.clicked.connect(self.monitoramento)
    self.button = self.findChild(QtWidgets.QPushButton, 'btnCadastro')
    self.button.clicked.connect(self.cadastro)
    self.show()

def monitoramento(self):
    os.system('python tela_monitoramento.py')

def cadastro(self):
    os.system('python tela_cadastrofotos.py')


app = QtWidgets.QApplication(sys.argv)
window = Ui()
app.exec_()
另一个脚本,我使用这些按钮调用脚本,正如您在调用后看到的,主窗口挂起,我被迫关闭整个系统:

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QInputDialog, QLineEdit, QMessageBox
import cv2


class App(QWidget):
def __init__(self):

    super().__init__()
    self.title = 'Tela cadastro usuários'

    self.initUI()

def initUI(self):
    self.setWindowTitle(self.title)
    # self.setGeometry(self.left, self.top, self.width, self.height)

    #self.getNome()
    self.getInteger()
    QMessageBox.about(self, "Confirmação", "Usuário cadastrado")

    # self.show()

def getNome(self):
    # from tela_monitoramento import known_face_names, face_names, known_face_encodings

    lista = []
    text, okPressed = QInputDialog.getText(self, "Nome do funcionário", "Insira o nome", 
  QLineEdit.Normal, "")
    if okPressed and text != '':
        lista.append(text)
        print(lista)

def getInteger(self):
    from PyQt5.QtWidgets import QInputDialog
    import cv2
    import os
    i, okPressed = QInputDialog.getInt(self, "Cadastro ID do usuário", "Insira o id:", 28, 0, 100, 1)
    if okPressed:
        print(i)

    # from PyQt5.QtWidgets import QInputDialog

    cam = cv2.VideoCapture(0)
    cam.set(3, 640)
    cam.set(4, 480)

    face_detector = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')

    # id na pessoa

    # face_id = input('\n Insira o id: <return> ==>  ')

    # print("\n [INFO] Iniciando a captura da face. Olhe para a câmera.")

    count = 0

    while (True):

        ret, img = cam.read()

        gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
        faces = face_detector.detectMultiScale(gray, 1.3, 5)

        for (x, y, w, h) in faces:
            cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)
            count += 1

            # Salvando a imagem em /usuarios
            cv2.imwrite("usuarios/funcionario." + str(i) + ".jpg", gray[y:y + h, x:x + w])

            cv2.imshow('Cadastro para reconhecimento', img)

        k = cv2.waitKey(100) & 0xff  # ESC para sair do vídeo
        if k == 27:
            break
        elif count >= 1:  # Tira 1 foto e depois fecha
            break

    # Fechando a câmera depois de tudo
   # print("\n [INFO] Fechando")
    cam.release()
    cv2.destroyAllWindows()



    if __name__ == '__main__':
   app = QApplication(sys.argv)
   ex = App()
   sys.exit(app.exec_())
导入系统 从PyQt5.QtWidgets导入QApplication、QWidget、QInputDialog、QLineEdit、QMessageBox 进口cv2 类应用程序(QWidget): 定义初始化(自): super()。\uuuu init\uuuuu() self.title='Tela cadastro usuários' self.initUI() def initUI(self): self.setWindowTitle(self.title) #self.setGeometry(self.left、self.top、self.width、self.height) #self.getNome() self.getInteger() QMessageBox.about(self,“Confirmaço”,“Usuário cadastrado”) #self.show() def getNome(自身): #从tela_监视器导入已知的面名称、面名称、已知面编码 lista=[] text,okPressed=QInputDialog.getText(self,“Nome do functionário”,“Insira o Nome”, QLineEdit.Normal(“”) 如果按下OK并显示文字!='': lista.append(文本) 打印(列表A) def getInteger(自): 从PyQt5.QtWidgets导入对话框 进口cv2 导入操作系统 i、 okPressed=QInputDialog.getInt(self,“地籍ID do usuário”,“Insira o ID:”,28,01000,1) 如果按了OK键: 印刷品(一) #从PyQt5.QtWidgets导入对话框 cam=cv2.视频捕获(0) 凸轮组(3640) 凸轮组(4480) face_detector=cv2.CascadeClassifier('haarcascade_frontalface_default.xml')) #佩索阿酒店 #面id=输入('\n Insira o id:==>') #打印(“\n[INFO]Iniciando a captura da face.Olhe para a c–mera.” 计数=0 虽然(正确): ret,img=cam.read() 灰色=cv2.CVT颜色(img,cv2.COLOR\U BGR2GRAY) 面部=面部检测器。检测多尺度(灰色,1.3,5) 对于面中的(x,y,w,h): cv2.矩形(img,(x,y),(x+w,y+h),(255,0,0),2) 计数+=1 #Salvando a imagem em/usuarios cv2.imwrite(“usuarios/functionario.+str(i)+.jpg”,灰色[y:y+h,x:x+w]) cv2.imshow(‘地籍调查’,img) k=cv2.等待键(100)和0xff 如果k==27: 打破 埃利夫计数>=1:#提拉1福埃博伊斯费查 打破 #这是图多市的一个停车场 #打印(“\n[INFO]Fechando”) cam.release() cv2.destroyAllWindows() 如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu': app=QApplication(sys.argv) ex=App() sys.exit(app.exec_())
欢迎来到StackOverflow!看起来您没有包含任何调试步骤的结果。您是否尝试过单步执行您的代码,以确保您的it按您认为的方式运行?如果您有,请编辑您的问题,以包括代码中的任何特定行为问题。如果没有,请先调试您的程序,然后提供这些详细信息。调试代码时会出现以下错误:
[WARN:0]全局C:\projects\opencv python\opencv\modules\videoio\src\cap\u msmf.cpp(674)SourceReaderCB::~SourceReaderCB正在终止异步回调