ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

PyQt5-界面跳转

2022-05-02 20:03:51  阅读:179  来源: 互联网

标签:__ 界面 pushButton self PyQt5 label 跳转 lineEdit MainWindow


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

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有