您好我想知道如何在textbox_1中键入字符串“word”(顶部一个框) 然后复制该字符串并在子进程命令中使用并将其输出到textbox_2(buttom框)而不使用信号
我尝试复制textbox_1,但该剂量似乎有效。
我的代码如下所示。
from PyQt4 import QtCore, QtGui
from PyQt4.QtGui import *
import subprocess
from subprocess import Popen, PIPE
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName(_fromUtf8("Form"))
Form.resize(840, 460)
self.textEdit_1 = QtGui.QTextEdit(Form)
self.textEdit_1.setGeometry(QtCore.QRect(0, 0, 291, 141))
self.textEdit_1.setObjectName(_fromUtf8("textEdit_1"))
self.textEdit_2 = QtGui.QTextEdit(Form)
self.textEdit_2.setGeometry(QtCore.QRect(0, 200, 301, 101))
self.textEdit_2.setObjectName(_fromUtf8("textEdit_2"))
self.pushButton = QtGui.QPushButton(Form)
self.pushButton.setGeometry(QtCore.QRect(370, 40, 381, 241))
self.pushButton.setObjectName(_fromUtf8("pushButton"))
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
Form.setWindowTitle(_translate("Form", "Form", None))
self.pushButton.setText(_translate("Form", "go", None))
self.pushButton.clicked.connect(self.run)
def run(self):
ff = self.textEdit_1.copy()
dog1 = subprocess.Popen('help ' + ff, stdout=subprocess.PIPE, shell=True)
self.textEdit_2.setText(dog1.stdout.read())
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
Form = QtGui.QWidget()
ui = Ui_Form()
ui.setupUi(Form)
Form.show()
sys.exit(app.exec_())
```
只使用一个子进程命令而没有来自text_box1的副本,因为输出右侧文本。
from PyQt4 import QtCore, QtGui
from PyQt4.QtGui import *
import subprocess
from subprocess import Popen, PIPE
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName(_fromUtf8("Form"))
Form.resize(840, 460)
self.textEdit_1 = QtGui.QTextEdit(Form)
self.textEdit_1.setGeometry(QtCore.QRect(0, 0, 291, 141))
self.textEdit_1.setObjectName(_fromUtf8("textEdit_1"))
self.textEdit_2 = QtGui.QTextEdit(Form)
self.textEdit_2.setGeometry(QtCore.QRect(0, 200, 301, 101))
self.textEdit_2.setObjectName(_fromUtf8("textEdit_2"))
self.pushButton = QtGui.QPushButton(Form)
self.pushButton.setGeometry(QtCore.QRect(370, 40, 381, 241))
self.pushButton.setObjectName(_fromUtf8("pushButton"))
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
Form.setWindowTitle(_translate("Form", "Form", None))
self.pushButton.setText(_translate("Form", "go", None))
self.pushButton.clicked.connect(self.run)
def run(self):
#ff = self.textEdit_1.copy()
dog1 = subprocess.Popen('help start', stdout=subprocess.PIPE, shell=True)
self.textEdit_2.setText(dog1.stdout.read())
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
Form = QtGui.QWidget()
ui = Ui_Form()
ui.setupUi(Form)
Form.show()
sys.exit(app.exec_())
```
答案 0 :(得分:0)