PyQt6遇到的问题:
import sys
import subprocess
from PyQt6.QtWidgets import QApplication, QWidget, QVBoxLayout, QPushButton, QPlainTextEdit
from PyQt6.QtCore import QProcess
class CommandRunner(QWidget):
def __init__(self):
super().__init__()
self.init_ui()
def init_ui(self):
self.setWindowTitle('Command Runner')
self.output_text_edit = QPlainTextEdit(self)
self.start_button = QPushButton('Start', self)
self.stop_button = QPushButton('Stop', self)
self.stop_button.setEnabled(False)
layout = QVBoxLayout(self)
layout.addWidget(self.output_text_edit)
layout.addWidget(self.start_button)
layout.addWidget(self.stop_button)
self.start_button.clicked.connect(self.start_command)
self.stop_button.clicked.connect(self.stop_command)
self.process = QProcess(self)
self.process.readyReadStandardOutput.connect(self.update_output)
self.process.finished.connect(self.command_finished)
def start_command(self):
cmd = "python ./JsFinder.py -u http://www.aiwin.fun -t 10"
self.process.start(cmd)
self.start_button.setEnabled(False)
self.stop_button.setEnabled(True)
def stop_command(self):
self.process.terminate()
def update_output(self):
output = self.process.readAllStandardOutput().data().decode()
self.output_text_edit.appendPlainText(output)
def command_finished(self):
self.start_button.setEnabled(True)
self.stop_button.setEnabled(False)
if __name__ == '__main__':
app = QApplication(sys.argv)
window = CommandRunner()
window.show()
sys.exit(app.exec())
我本来的意愿是当点击start按钮的时候,自动执行命令并将命令的输出实时同步到QPlainTextEdit中,点击停止按钮则会自动停止命令的继续执行,但是现在我的代码当我点击start的时候,没有任何的反应,我要怎么修改代码解决问题?