其他分享
首页 > 其他分享> > PyQt5-界面跳转

PyQt5-界面跳转

作者:互联网

PyQt5-界面跳转

代码

import pymysql
import sys
from single_insert import Ui_MainWindow
from Register import Ui_Form

from PyQt5.QtWidgets import QApplication,QMainWindow,QMessageBox,QWidget

class Run_MainWindow(Ui_MainWindow, QMainWindow):
    def __init__(self):
        super(Run_MainWindow, self).__init__()
        self.setupUi(self)
        self.lineEdit=self.lineEdit
        self.label_3=self.label_3
        self.label_2=self.label_2
        self.lineEdit_2 = self.lineEdit_2
        self.label = self.label
        self.lineEdit_3 = self.lineEdit_3
        self.pushButton.clicked.connect(self.insertTBuarea)
        self.pushButton_2=self.pushButton_2
        self.pushButton_3=self.pushButton_3


    # 数据库——增一条数据功能
    def insertTBuarea(self):
        print("面积:{0},功能:{1}".format(self.lineEdit_2.text(),self.lineEdit_3.text()))

        global a, b
        a=self.lineEdit_2.text()
        b=self.lineEdit_3.text()

        # a,b格式错误则弹出对话框,先省略

        # 打开数据库连接
        db = pymysql.connect(host='localhost',
                             user='root',
                             password='123456',
                             database='sportsarear&b')
        sql = "INSERT INTO uarea(asqure,afuncation) VALUES ('{0}','{1}')".format(a, b)
        print(sql)
        # 使用cursor()方法获取操作游标
        cursor = db.cursor()
        try:
            # 执行sql语句
            cursor.execute(sql)
            # 提交到数据库执行
            db.commit()
            # 提交成功显示一个对话框
            self.show_messages()
        except:
            # 如果发生错误则回滚
            print("数据提交失败!")
            db.rollback()
        # 关闭数据库连接
        db.close()

    def show_messages(self):
        QMessageBox.information(self,"增添数据","任务完成",QMessageBox.Yes)

class Run_register(Ui_Form,QWidget):
    def __init__(self):
        super(Run_register, self).__init__()




if __name__ == '__main__':
    app = QApplication(sys.argv)
    MainWindow = Run_MainWindow()
    Register=Run_register()

    #通过按钮将两个窗体关联
    btn = MainWindow.pushButton_3
    btn.clicked.connect(Register.show)

    MainWindow.show()
    sys.exit(app.exec())

标签:__,界面,pushButton,self,PyQt5,label,跳转,lineEdit,MainWindow
来源: https://www.cnblogs.com/Frey-Li/p/16216618.html