编程语言
首页 > 编程语言> > 基于Python+Pyqt5应用程序开发

基于Python+Pyqt5应用程序开发

作者:互联网

介绍你的那个她/他

1. UI —MainWindow设计界面及代码

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file '/media/sf_data/onemore_tjj/Again_tjj/MainWindow.ui'
#
# Created by: PyQt5 UI code generator 5.14.1
#
# WARNING! All changes made in this file will be lost!


from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(788, 634)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.groupBox_2 = QtWidgets.QGroupBox(self.centralwidget)
        self.groupBox_2.setGeometry(QtCore.QRect(40, 270, 691, 321))
        self.groupBox_2.setObjectName("groupBox_2")
        self.txtResume = QtWidgets.QTextEdit(self.groupBox_2)
        self.txtResume.setGeometry(QtCore.QRect(10, 30, 671, 281))
        self.txtResume.setObjectName("txtResume")
        self.butGenerate = QtWidgets.QPushButton(self.centralwidget)
        self.butGenerate.setGeometry(QtCore.QRect(390, 230, 101, 51))
        self.butGenerate.setObjectName("butGenerate")
        self.groupBox_3 = QtWidgets.QGroupBox(self.centralwidget)
        self.groupBox_3.setGeometry(QtCore.QRect(500, 10, 231, 271))
        self.groupBox_3.setObjectName("groupBox_3")
        self.label_6 = QtWidgets.QLabel(self.groupBox_3)
        self.label_6.setGeometry(QtCore.QRect(6, 30, 221, 241))
        self.label_6.setMinimumSize(QtCore.QSize(221, 0))
        self.label_6.setMaximumSize(QtCore.QSize(221, 16777215))
        self.label_6.setText("")
        self.label_6.setPixmap(QtGui.QPixmap(":/tjj.jpg"))
        self.label_6.setObjectName("label_6")
        self.label_6.setScaledContents(True)    #图片自适应
        self.groupBox = QtWidgets.QGroupBox(self.centralwidget)
        self.groupBox.setGeometry(QtCore.QRect(30, 20, 231, 201))
        self.groupBox.setObjectName("groupBox")
        self.txtName = QtWidgets.QLineEdit(self.groupBox)
        self.txtName.setGeometry(QtCore.QRect(50, 30, 151, 25))
        self.txtName.setObjectName("txtName")
        self.label = QtWidgets.QLabel(self.groupBox)
        self.label.setGeometry(QtCore.QRect(10, 32, 67, 17))
        self.label.setObjectName("label")
        self.txtRelationship = QtWidgets.QLineEdit(self.groupBox)
        self.txtRelationship.setGeometry(QtCore.QRect(50, 60, 151, 25))
        self.txtRelationship.setObjectName("txtRelationship")
        self.label_2 = QtWidgets.QLabel(self.groupBox)
        self.label_2.setGeometry(QtCore.QRect(6, 90, 67, 17))
        self.label_2.setObjectName("label_2")
        self.txtHobby = QtWidgets.QLineEdit(self.groupBox)
        self.txtHobby.setGeometry(QtCore.QRect(48, 120, 151, 25))
        self.txtHobby.setObjectName("txtHobby")
        self.txtCharacter = QtWidgets.QLineEdit(self.groupBox)
        self.txtCharacter.setGeometry(QtCore.QRect(48, 150, 151, 25))
        self.txtCharacter.setObjectName("txtCharacter")
        self.label_4 = QtWidgets.QLabel(self.groupBox)
        self.label_4.setGeometry(QtCore.QRect(6, 122, 67, 17))
        self.label_4.setObjectName("label_4")
        self.label_3 = QtWidgets.QLabel(self.groupBox)
        self.label_3.setGeometry(QtCore.QRect(6, 60, 67, 17))
        self.label_3.setObjectName("label_3")
        self.label_5 = QtWidgets.QLabel(self.groupBox)
        self.label_5.setGeometry(QtCore.QRect(6, 153, 67, 17))
        self.label_5.setObjectName("label_5")
        self.txtSpecialty = QtWidgets.QLineEdit(self.groupBox)
        self.txtSpecialty.setGeometry(QtCore.QRect(49, 90, 151, 25))
        self.txtSpecialty.setObjectName("txtSpecialty")
        self.groupBox_5 = QtWidgets.QGroupBox(self.centralwidget)
        self.groupBox_5.setGeometry(QtCore.QRect(270, 20, 221, 201))
        self.groupBox_5.setObjectName("groupBox_5")
        self.label_7 = QtWidgets.QLabel(self.groupBox_5)
        self.label_7.setGeometry(QtCore.QRect(10, 40, 67, 17))
        self.label_7.setObjectName("label_7")
        self.label_8 = QtWidgets.QLabel(self.groupBox_5)
        self.label_8.setGeometry(QtCore.QRect(10, 70, 67, 17))
        self.label_8.setObjectName("label_8")
        self.label_9 = QtWidgets.QLabel(self.groupBox_5)
        self.label_9.setGeometry(QtCore.QRect(10, 100, 67, 17))
        self.label_9.setObjectName("label_9")
        self.label_10 = QtWidgets.QLabel(self.groupBox_5)
        self.label_10.setGeometry(QtCore.QRect(10, 130, 67, 17))
        self.label_10.setObjectName("label_10")
        self.label_11 = QtWidgets.QLabel(self.groupBox_5)
        self.label_11.setGeometry(QtCore.QRect(10, 160, 67, 17))
        self.label_11.setObjectName("label_11")
        self.txtHair = QtWidgets.QLineEdit(self.groupBox_5)
        self.txtHair.setGeometry(QtCore.QRect(60, 40, 113, 25))
        self.txtHair.setObjectName("txtHair")
        self.txtHeight = QtWidgets.QLineEdit(self.groupBox_5)
        self.txtHeight.setGeometry(QtCore.QRect(60, 70, 113, 25))
        self.txtHeight.setObjectName("txtHeight")
        self.txtWeight = QtWidgets.QLineEdit(self.groupBox_5)
        self.txtWeight.setGeometry(QtCore.QRect(60, 100, 113, 25))
        self.txtWeight.setObjectName("txtWeight")
        self.txtOffice = QtWidgets.QLineEdit(self.groupBox_5)
        self.txtOffice.setGeometry(QtCore.QRect(60, 130, 113, 25))
        self.txtOffice.setObjectName("txtOffice")
        self.txtAddress = QtWidgets.QLineEdit(self.groupBox_5)
        self.txtAddress.setGeometry(QtCore.QRect(60, 160, 113, 25))
        self.txtAddress.setObjectName("txtAddress")
        self.label_14 = QtWidgets.QLabel(self.groupBox_5)
        self.label_14.setGeometry(QtCore.QRect(175, 73, 67, 17))
        self.label_14.setObjectName("label_14")
        self.label_15 = QtWidgets.QLabel(self.groupBox_5)
        self.label_15.setGeometry(QtCore.QRect(175, 101, 67, 17))
        self.label_15.setObjectName("label_15")
        MainWindow.setCentralWidget(self.centralwidget)

        self.retranslateUi(MainWindow)
        self.butGenerate.clicked.connect(MainWindow.Generate)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "介绍你青春里的那个她"))
        self.groupBox_2.setTitle(_translate("MainWindow", "简介:"))
        self.butGenerate.setText(_translate("MainWindow", "生成"))
        self.groupBox_3.setTitle(_translate("MainWindow", "照片"))
        self.groupBox.setTitle(_translate("MainWindow", "我的朋友:"))
        self.label.setText(_translate("MainWindow", "姓名:"))
        self.label_2.setText(_translate("MainWindow", "特长:"))
        self.label_4.setText(_translate("MainWindow", "爱好:"))
        self.label_3.setText(_translate("MainWindow", "关系:"))
        self.label_5.setText(_translate("MainWindow", "性格:"))
        self.groupBox_5.setTitle(_translate("MainWindow", "简介:"))
        self.label_7.setText(_translate("MainWindow", "发型:"))
        self.label_8.setText(_translate("MainWindow", "身高:"))
        self.label_9.setText(_translate("MainWindow", "体重:"))
        self.label_10.setText(_translate("MainWindow", "职务:"))
        self.label_11.setText(_translate("MainWindow", "住址:"))
        self.label_14.setText(_translate("MainWindow", "m"))
        self.label_15.setText(_translate("MainWindow", "kg"))
import picture_rc

2. 应用程序代码

# 系统包
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
# 项目包
from Ui_MainWindow import Ui_MainWindow
class Cjianjie:
    hair = ""
    height = ""
    weight = ""
    office = ""
    address = ""
    bmi=0.0
    def OutputHair(self):
        strOutput = "她有一头乌黑亮丽的黑" + self.hair
        return strOutput
    def OutputHeight(self):
        strOutput = "她长的不算很高,"+ self.height + "米左右"
        return strOutput
    def OutputWeight(self):
        strOutput = "她身材不胖,才" + self.weight + "公斤"
        return strOutput

    def OutputOffice(self):
        strOutput = "她在班里是" + self.office + "也是因为她才记得了那首诗,曾经沧海难为水,除去巫山不是云"
        return strOutput
    def OutputAddress(self):
        strOutput = "她家住在"  + self.address + "K41旁的我和她不是顺路,只是在意每一次的路过"
        return strOutput
    def OutputResume(self):
        strOutput = "    " + self.OutputHair() + ","
        strOutput = strOutput + self.OutputHeight() + ","
        strOutput = strOutput + self.OutputWeight() + ","
        strOutput = strOutput + self.OutputOffice() + "。"
        strOutput = strOutput + self.OutputAddress() + "。"
        return strOutput
class CFriend(Cjianjie):
    name = ""
    restionship = ""
    speciatly = ""
    hobby = ""
    character = ""
    def OutputName(self):
        strOutput = "她就是笑容值得等待一千万年的" + self.name
        return strOutput
    def OutputRestionship(self):
        strOutput = "她是我的"+ self.restionship + ";高中两年同窗,忘不了早自习一起被赶出去补作业,忘不了背不过英语去后排罚站,忘不了她曾谢绝了我的巧克力" 
        return strOutput
    def OutputSpecialty(self):
        strOutput = "她擅长" + self.speciatly + ",她那明亮的眼睛中,荡漾这一池清波,清波上荡漾着聪明与智慧;简单纯粹,风华绝代"
        return strOutput
    def OutputHobby(self):
        strOutput = "她爱" + self.hobby + ",老看她发逛街的朋友圈,差点忘了她眼里也有山河、星辰、大海和天空,哈哈,她和我都不曾缺失发现美的眼睛" 
        return strOutput
    def OutputCharacter(self):
        strOutput = "她性格" + self.character + ",尤记开学发书,传给你的是书,她却还给我一句谢谢和一个微笑,也曾开玩笑问她以后要不要嫁入豪门,她却说:“靠自己!”" 
        return strOutput

    def OutputResume(self):
        strOutput= Cjianjie.OutputResume(self)
        strOutput = strOutput+ self.OutputName() + ","
        strOutput = strOutput + self.OutputRestionship() + "。"
        strOutput = strOutput + self.OutputSpecialty() + "。"
        strOutput = strOutput + self.OutputHobby() + "。"
        strOutput = strOutput + self.OutputCharacter() + "。"
        return strOutput

class CMainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
    def __init__(self, parent = None):
        super(CMainWindow, self).__init__(parent)
        self.setupUi(self)

        # 主窗体设置
        self.show()


    def Generate(self):
        f = CFriend()
        f.hair = self.txtHair.text()
        f.height = self.txtHeight.text()
        f.weight = self.txtWeight.text()
        f.office = self.txtOffice.text()
        f.address = self.txtAddress.text()
        f.name = self.txtName.text()
        f.restionship = self.txtRelationship.text()
        f.speciatly= self.txtSpecialty.text()
        f.character= self.txtCharacter.text()
        f.hobby = self.txtHobby.text()
       
        
        self.txtResume.setText(f.OutputResume())


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = CMainWindow()
    sys.exit(app.exec_())

3. 视频播放程序图片及代码

import numpy as np
import cv2 as cv
cap = cv.VideoCapture('video1.avi')
while cap.isOpened():
    ret, frame = cap.read()
    # if frame is read correctly ret is True
    if not ret:
        print("Can't receive frame (stream end?). Exiting ...")
        break
    # show gray picture
    #gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
    #cv.imshow('frame', gray)
    cv.imshow('frame', frame)
    if cv.waitKey(1) == ord('q'):
        break
cap.release()
cv.destroyAllWindows()

4. 呈现效果

标签:Python,self,程序开发,Pyqt5,label,groupBox,QtCore,MainWindow,strOutput
来源: https://blog.csdn.net/YZ807680/article/details/117931386