My program is AI based. I have seen all post regarding Pyqt set text in stackoverflow. I want to setText in lineEdit when Auto(AI) button is clicked.
def AI_click(self):
#self.lineEdit.setText("YO")
os.system('python detect_video.py --weights ./checkpoints/custom-416 --size 416 --model yolov4 --video 0 --plate')
#self.lineEdit.setText(line1)
Basically AI button executing py file and it print string. How can I use another.py string in this GUI py file. When my program execute py file it's no longer remember self.lineEdit.setText(line1)
and also string.
class Ui_Dialog(object):
def setupUi(self, Dialog,var):
Dialog.setObjectName("Dialog")
Dialog.resize(1120, 850)
Dialog.setStyleSheet("QDialog#Dialog{\n""background-color:
qlineargradient(spread:pad,x1:0.0113636, y1:0.966, x2:1, y2:0,
stop:0 rgba(0, 0, 0, 255), stop:1 rgba(255, 255, 255, 255))\n"
"\n"
"}\n"
"\n"
"")
self.widget = QtWidgets.QWidget(Dialog)
self.widget.setGeometry(QtCore.QRect(0, 0, 201, 851))
self.widget.setStyleSheet("\n"
"background-color: rgb(100, 100, 100);")
self.widget.setObjectName("widget")
self.dashboardButton = QtWidgets.QPushButton(self.widget)
self.dashboardButton.setGeometry(QtCore.QRect(0, 250, 201, 51))
self.dashboardButton.setStyleSheet("QPushButton {\n"
" background-color: rgb(255, 255, 255);\n"
" color: #FFFFFF;\n"
" \n"
" padding: 2px;\n"
" font: bold 20px; color:black;\n"
" \n"
" \n"
" }\n"
"QPushButton:hover {\n"
" background-color: rgb(98, 98, 98);\n"
"}")
self.dashboardButton.setObjectName("dashboardButton")
self.dashboardButton_2 = QtWidgets.QPushButton(self.widget)
self.dashboardButton_2.setGeometry(QtCore.QRect(0, 370, 201, 51))
self.dashboardButton_2.setStyleSheet("QPushButton {\n"
" background-color: rgb(255, 255, 255);\n"
" color: #FFFFFF;\n"
" \n"
" padding: 2px;\n"
" font: bold 20px; color:black;\n"
" \n"
" \n"
" }\n"
"QPushButton:hover {\n"
" background-color: rgb(98, 98, 98);\n"
"}")
self.dashboardButton_2.setObjectName("dashboardButton_2")
self.label = QtWidgets.QLabel(Dialog)
self.label.setGeometry(QtCore.QRect(250, 20, 171, 91))
self.label.setStyleSheet("font-size: 30px;\n"
"font: bold;\n"
"")
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(Dialog)
self.label_2.setGeometry(QtCore.QRect(630, 70, 416, 416))
self.label_2.setText("")
self.label_2.setPixmap(QtGui.QPixmap("D:/Downloads/numplate.jpg"))
self.label_2.setScaledContents(True)
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(Dialog)
self.label_3.setGeometry(QtCore.QRect(640, 530, 401, 241))
self.label_3.setText("")
self.label_3.setPixmap(QtGui.QPixmap("D:/Downloads/20886263.jpg"))
self.label_3.setScaledContents(True)
self.label_3.setObjectName("label_3")
self.lineEdit = QtWidgets.QLineEdit(Dialog)
#self.lineEdit.setText("YO")
# if string!=None:
# print("called")
# print(string)
# self.lineEdit.setText(string)
self.lineEdit.setGeometry(QtCore.QRect(300, 280, 221, 41))
self.lineEdit.setObjectName("lineEdit")
self.lineEdit_2 = QtWidgets.QLineEdit(Dialog)
self.lineEdit_2.setGeometry(QtCore.QRect(300, 360, 221, 41))
self.lineEdit_2.setObjectName("lineEdit_2")
self.label_4 = QtWidgets.QLabel(Dialog)
self.label_4.setGeometry(QtCore.QRect(300, 260, 81, 16))
self.label_4.setObjectName("label_4")
self.label_5 = QtWidgets.QLabel(Dialog)
self.label_5.setGeometry(QtCore.QRect(300, 340, 81, 16))
self.label_5.setObjectName("label_5")
self.pushButton = QtWidgets.QPushButton(Dialog)
self.pushButton.setGeometry(QtCore.QRect(420, 430, 101, 31))
self.pushButton.setObjectName("pushButton")
self.pushButton_AI = QtWidgets.QPushButton(Dialog)
self.pushButton_AI.setGeometry(QtCore.QRect(300, 430, 101, 31))
self.pushButton_AI.setObjectName("pushButton_AI")
print("car:"+var)
self.pushButton.clicked.connect(self.clickme)
self.pushButton_AI.clicked.connect(self.AI_click)
lineEdit= self.lineEdit
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def AI_click(self):
#self.lineEdit.setText("YO")
os.system('python detect_video.py --weights ./checkpoints/custom-416 --size 416 --model yolov4 --video 0 --plate')
#self.lineEdit.setText(line1)
def clickme(self):
np=self.lineEdit.text()
cnic=self.lineEdit_2.text()
table_data(np,cnic)
# printing pressed
print(np+cnic)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
self.dashboardButton.setText(_translate("Dialog", "Dashboard"))
self.dashboardButton_2.setText(_translate("Dialog", "Record"))
self.label.setText(_translate("Dialog", "Dashboard"))
self.label_4.setText(_translate("Dialog", "Number Plate:"))
self.label_5.setText(_translate("Dialog", "CNIC:"))
self.pushButton.setText(_translate("Dialog", "Save "))
self.pushButton_AI.setText(_translate("Dialog", "Auto"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
var=""
ui.setupUi(Dialog,var)
Dialog.show()
sys.exit(app.exec_())
Thanks to @musicamante Instead of using os.system('python detect_video.py --weights./checkpoints/custom-416 --size 416 --model yolov4 --video 0 --plate')
use this
def AI_click(self):
s=subprocess.Popen(['python', 'detect_video.py' ,'--weights'
,'./checkpoints/custom-416' ,'--size', '416' ,
'--model', 'yolov4' ,'--video', '0' ,'--plate'], stdout=subprocess.PIPE)
output = s.stdout.read()
s=output.decode()
self.lineEdit.setText(s)
In other.py file there should be print function
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.