4.14今日总结

今天学习了pyqt5的控件布局

page1 = QWidget()
        layout1 = QVBoxLayout(page1)
        label1 = QLabel('专注度检测')
        label1.setAlignment(Qt.AlignHCenter)
        label1.setFont(QFont("宋体", 23))
        layout1.addWidget(label1)
        layout1.addSpacing(20)
        self.timer = QTimer(self)
        self.timer.timeout.connect(self.update_time)
        self.label_time = QLabel(self)
        self.button1 = QPushButton('开始学习', self)
        self.button2 = QPushButton('结束学习', self)
        layout1.addWidget(self.label_time)
        hbox = QHBoxLayout()
        hbox.addWidget(self.button1)
        hbox.addWidget(self.button2)
        layout1.addLayout(hbox)
        layout1.setAlignment(Qt.AlignTop)
        # 摄像头视野
        self.camera = QCamera()  # 创建摄像头对象
        self.camera_viewfinder = QCameraViewfinder()
        layout1.addWidget(self.camera_viewfinder)

        page1.setStyleSheet("background-color: #fff;")
        self.stack_widget.addWidget(page1)
        self.button1.clicked.connect(self.start_camera)
        self.button2.clicked.connect(self.stop_camera)


        page2 = QWidget()
        layout2 = QHBoxLayout(page2)
        label2 = QLabel('每日记录')
        layout2.addWidget(label2)
        page2.setStyleSheet("background-color: #fff;")
        self.stack_widget.addWidget(page2)

        # 个人资料显示以及修改
        conn = pymysql.connect(host='localhost', user='root', password='ykw031124', db='bb')
        cursor = conn.cursor()
        query = "SELECT * FROM information WHERE id=%s AND pwd=%s"
        cursor.execute(query, (username, password))
        result = cursor.fetchone()
        name = result[1]
        classname = result[2]
        page3 = QWidget()
        layout3 = QVBoxLayout(page3)
        label31 = QLabel('个人资料查看及修改')
        label31.setAlignment(Qt.AlignHCenter)
        label31.setFont(QFont("宋体", 23))
        layout32 = QHBoxLayout()
        label32 = QLabel('姓名:')
        label32.setFont(QFont("宋体", 20))
        label32.setAlignment(Qt.AlignHCenter)
        self.label32x = QLineEdit(name)
        self.label32x.setAlignment(Qt.AlignLeft)
        layout32.addWidget(label32)
        layout32.addWidget(self.label32x)

        layout34 = QHBoxLayout()
        label34 = QLabel('班级:')
        label34.setFont(QFont("宋体", 20))
        label34.setAlignment(Qt.AlignHCenter)
        self.label34x = QLineEdit(classname)
        layout34.addWidget(label34)
        layout34.addWidget(self.label34x)

        layout33 = QHBoxLayout()
        label331 = QLabel('学号:' + username+'(学号不可修改)')
        label331.setAlignment(Qt.AlignHCenter)
        label331.setFont(QFont("宋体", 15))
        layout33.addWidget(label331)

        button = QPushButton('确认')
        button.clicked.connect(self.reviseinf)
        button.setFixedSize(120, 40)
        button.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)

        # 再将整个子布局添加到主布局中
        layout3.addWidget(label31)
        layout3.addStretch(1)
        layout3.addLayout(layout33)
        layout3.addStretch(1)
        layout3.addLayout(layout32)
        layout3.addStretch(1)
        layout3.addLayout(layout34)
        layout3.addStretch(1)
        layout3.addWidget(button, alignment=Qt.AlignHCenter)

        page3.setStyleSheet("background-color: #fff;")
        self.stack_widget.addWidget(page3)



        page4 = QWidget()
        layout4 = QVBoxLayout(page4)
        layout4.setAlignment(Qt.AlignTop)
        label41 = QLabel('修改密码')
        label41.setAlignment(Qt.AlignHCenter)
        label41.setFont(QFont("宋体", 23))
        old_password_layout = QHBoxLayout()
        old_password_label = QLabel('旧密码:')
        old_password_label.setFont(QFont("宋体", 20))
        self.old_password_edit = QLineEdit()
        old_password_layout.addWidget(old_password_label)
        old_password_layout.addWidget(self.old_password_edit)
        new_password_layout = QHBoxLayout()
        new_password_label = QLabel('新密码:')
        new_password_label.setFont(QFont("宋体", 20))
        self.new_password_edit = QLineEdit()
        new_password_layout.addWidget(new_password_label)
        new_password_layout.addWidget(self.new_password_edit)
        confirm_password_layout = QHBoxLayout()
        confirm_password_label = QLabel('确认密码:')
        confirm_password_label.setFont(QFont("宋体", 20))
        self.confirm_password_edit = QLineEdit()
        confirm_password_layout.addWidget(confirm_password_label)
        confirm_password_layout.addWidget(self.confirm_password_edit)
        confirm_button = QPushButton('确认')
        confirm_button.clicked.connect(self.revise)
        confirm_button.setFixedSize(120, 40)
        confirm_button.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        layout4.addWidget(label41)
        layout4.setSpacing(90)
        layout4.addLayout(old_password_layout)
        layout4.addLayout(new_password_layout)
        layout4.addLayout(confirm_password_layout)
        layout4.addWidget(confirm_button, alignment=Qt.AlignHCenter)
        page4.setStyleSheet("background-color: #fff;")
        self.stack_widget.addWidget(page4)

        # 将左侧和右侧部件添加到主布局中
        main_layout = QHBoxLayout()
        main_layout.addWidget(left_widget)
        main_layout.addWidget(self.stack_widget)
        main_layout.setStretch(0, 1)
        main_layout.setStretch(1, 4)

        main_widget = QWidget()
        main_widget.setLayout(main_layout)
        self.setCentralWidget(main_widget)

        # 连接按钮的单击信号到相应的页面
        self.btn_1.clicked.connect(lambda: self.stack_widget.setCurrentIndex(0))
        self.btn_2.clicked.connect(lambda: self.stack_widget.setCurrentIndex(1))
        self.btn_3.clicked.connect(lambda: self.stack_widget.setCurrentIndex(2))
        self.btn_4.clicked.connect(lambda: self.stack_widget.setCurrentIndex(3))

 

posted @ 2023-04-14 23:02  不洗澡超酷  阅读(12)  评论(0)    收藏  举报