PyQt5大学课程表

简介: PyQt5大学课程表

闲来无事,暑假自学了PyQt5,在开学后用PyQt5做了一个简单的课程表,避免了每次都需要去教务看课表的麻烦。喜欢的可以支持一下。
b35527806a5a491fb8a2c71e96f67501.jpg

代码

import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
class CourseTimetable(QMainWindow):
    def __init__(self):
        super(CourseTimetable, self).__init__()
        self.initUI()
    def initUI(self):
        self.setWindowTitle("Course")
        self.resize(560,950)
        '''布局'''
        widget = QWidget()
        grid = QGridLayout()
        '''头部'''
        name = QLabel('课程表')
        name.setStyleSheet('font-size:25px;')
        grid.addWidget(name,0,0,1,2)
        week = QPushButton('第一周')
        week.setIcon(QIcon('week.ico'))
        grid.addWidget(week,0,5,1,2)
        more = QPushButton()
        more.setIcon(QIcon('threepoint.ico'))
        grid.addWidget(more,0,7,1,1)
        '''课表框架'''
        label1 = QLabel('节次/时间')
        label1.setAlignment(Qt.AlignCenter)
        label1.setStyleSheet('background-color:Gainsboro;')
        grid.addWidget(label1, 1, 0, 1, 1)
        label2 = QLabel('星期一')
        label2.setAlignment(Qt.AlignCenter)
        label2.setStyleSheet('background-color:Gainsboro;')
        grid.addWidget(label2, 1, 1, 1, 1)
        label3 = QLabel('星期二')
        label3.setAlignment(Qt.AlignCenter)
        label3.setStyleSheet('background-color:Gainsboro;')
        grid.addWidget(label3, 1, 2, 1, 1)
        label4 = QLabel('星期三')
        label4.setAlignment(Qt.AlignCenter)
        label4.setStyleSheet('background-color:Gainsboro;')
        grid.addWidget(label4, 1, 3, 1, 1)
        label5 = QLabel('星期四')
        label5.setAlignment(Qt.AlignCenter)
        label5.setStyleSheet('background-color:Gainsboro;')
        grid.addWidget(label5, 1, 4, 1, 1)
        label6 = QLabel('星期五')
        label6.setAlignment(Qt.AlignCenter)
        label6.setStyleSheet('background-color:Gainsboro;')
        grid.addWidget(label6, 1, 5, 1, 1)
        label7 = QLabel('星期六')
        label7.setAlignment(Qt.AlignCenter)
        label7.setStyleSheet('background-color:Gainsboro;')
        grid.addWidget(label7, 1, 6, 1, 1)
        label8 = QLabel('星期日')
        label8.setAlignment(Qt.AlignCenter)
        label8.setStyleSheet('background-color:Gainsboro;')
        grid.addWidget(label8, 1, 7, 1, 1)
        label_12 = QLabel()
        label_12.setText(
            "<font style = 'font-size:15px;font-weight: bold;text-align:center;'>第一节</font>"
            "<br/>" "<br/>"
            "<font style = 'font-size:13px;'>08:15~09:00</font>"
            "<br/>""<br/>"
            "<font style = 'font-size:15px;font-weight: bold;'>第二节</font>"
            "<br/>" "<br/>"
            "<font style = 'font-size:13px;'>09:05~09:50</font>"
        )
        label_12.setAlignment(Qt.AlignCenter)
        label_12.setStyleSheet('background-color: LightGreen;')
        grid.addWidget(label_12,2,0,4,1)
        label_34 = QLabel()
        label_34.setText(
            "<font style = 'font-size:15px;font-weight: bold;'>第三节</font>"
            "<br/>" "<br/>"
            "<font style = 'font-size:13px;'>08:15~09:00</font>"
            "<br/>""<br/>"
            "<font style = 'font-size:15px;font-weight: bold;'>第四节</font>"
            "<br/>" "<br/>"
            "<font style = 'font-size:13px;'>09:05~09:50</font>"
        )
        label_34.setAlignment(Qt.AlignCenter)
        label_34.setStyleSheet('background-color: MediumOrchid;')
        grid.addWidget(label_34, 6,0,4,1)
        label_56 = QLabel()
        label_56.setText(
            "<font style = 'font-size:15px;font-weight: bold;'>第五节</font>"
            "<br/>" "<br/>"
            "<font style = 'font-size:13px;'>08:15~09:00</font>"
            "<br/>""<br/>"
            "<font style = 'font-size:15px;font-weight: bold;'>第六节</font>"
            "<br/>" "<br/>"
            "<font style = 'font-size:13px;'>09:05~09:50</font>"
        )
        label_56.setAlignment(Qt.AlignCenter)
        label_56.setStyleSheet('background-color: LightGreen;')
        grid.addWidget(label_56, 10, 0, 4, 1)
        label_78 = QLabel('')
        label_78.setText(
            "<font style = 'font-size:15px;font-weight: bold;'>第七节</font>"
            "<br/>" "<br/>"
            "<font style = 'font-size:13px;'>08:15~09:00</font>"
            "<br/>""<br/>"
            "<font style = 'font-size:15px;font-weight: bold;'>第八节</font>"
            "<br/>" "<br/>"
            "<font style = 'font-size:13px;'>09:05~09:50</font>"
        )
        label_78.setAlignment(Qt.AlignCenter)
        label_78.setStyleSheet('background-color: MediumOrchid;')
        grid.addWidget(label_78, 14, 0, 4, 1)
        label_9 = QLabel('')
        label_9.setText(
            "<font style = 'font-size:15px;font-weight: bold;'>第九节</font>"
            "<br/>""<br/>"
            "<font style = 'font-size:13px;'>08:15~09:00</font>"
            "<br/>""<br/>"
            "<font style = 'font-size:15px;font-weight: bold;'>第十节</font>"
            "<br/>" "<br/>"
            "<font style = 'font-size:13px;'>09:05~09:50</font>"
            "<br/>""<br/>"
            "<font style = 'font-size:15px;font-weight: bold;'>第十一节</font>"
            "<br/>" "<br/>"
            "<font style = 'font-size:13px;'>09:05~09:50</font>"
        )
        label_9.setAlignment(Qt.AlignCenter)
        label_9.setStyleSheet('background-color:LightSteelBlue;')
        grid.addWidget(label_9, 18, 0, 5, 1)
        '''课表内容'''
        '''星期一'''
        Monday_12 = QTextEdit('')
        Monday_12.setStyleSheet('font-size:16px;')
        grid.addWidget(Monday_12, 2, 1, 4, 1)
        Monday_34 = QTextEdit('')
        Monday_34.setStyleSheet('font-size:16px;')
        grid.addWidget(Monday_34,6,1,4,1)
        Monday_56 = QTextEdit('')
        Monday_56.setStyleSheet('font-size:16px;')
        grid.addWidget(Monday_56, 10, 1, 4, 1)
        Monday_78 = QTextEdit('')
        Monday_78.setStyleSheet('font-size:16px;')
        grid.addWidget(Monday_78, 14, 1, 4, 1)
        Monday_9 = QTextEdit('')
        Monday_9.setStyleSheet('font-size:16px;')
        grid.addWidget(Monday_9, 18, 1, 5, 1)
        '''星期二'''
        Tuesday_12 = QTextEdit('')
        Tuesday_12.setStyleSheet('font-size:16px;')
        grid.addWidget(Tuesday_12, 2, 2, 4, 1)
        Tuesday_34 = QTextEdit('')
        Tuesday_34.setStyleSheet('font-size:16px;')
        grid.addWidget(Tuesday_34, 6, 2, 4, 1)
        Tuesday_56 = QTextEdit('')
        Tuesday_56.setStyleSheet('font-size:16px;')
        grid.addWidget(Tuesday_56, 10, 2, 4, 1)
        Tuesday_78 = QTextEdit('')
        Tuesday_78.setStyleSheet('font-size:16px;')
        grid.addWidget(Tuesday_78, 14, 2, 4, 1)
        Tuesday_9 = QTextEdit('')
        Tuesday_9.setStyleSheet('font-size:16px;')
        grid.addWidget(Tuesday_9, 18, 2, 5, 1)
        '''星期三'''
        Wednesday_12 = QTextEdit('')
        Wednesday_12.setStyleSheet('font-size:16px;')
        grid.addWidget(Wednesday_12, 2, 3, 4, 1)
        Wednesday_34 = QTextEdit('')
        Wednesday_34.setStyleSheet('font-size:16px;')
        grid.addWidget(Wednesday_34, 6, 3, 4, 1)
        Wednesday_56 = QTextEdit('')
        Wednesday_56.setStyleSheet('font-size:16px;')
        grid.addWidget(Wednesday_56, 10, 3, 4, 1)
        Wednesday_78 = QTextEdit('')
        Wednesday_78.setStyleSheet('font-size:16px;')
        grid.addWidget(Wednesday_78, 14, 3, 4, 1)
        Wednesday_9 = QTextEdit('')
        Wednesday_9.setStyleSheet('font-size:16px;')
        grid.addWidget(Wednesday_9, 18, 3, 5, 1)
        '''星期四'''
        Thursday_12 = QTextEdit('')
        Thursday_12.setStyleSheet('font-size:16px;')
        grid.addWidget(Thursday_12, 2, 4, 4, 1)
        Thursday_34 = QTextEdit('')
        Thursday_34.setStyleSheet('font-size:16px;')
        grid.addWidget(Thursday_34, 6, 4, 4, 1)
        Thursday_56 = QTextEdit('')
        Thursday_56.setStyleSheet('font-size:16px;')
        grid.addWidget(Thursday_56, 10, 4, 4, 1)
        Thursday_78 = QTextEdit('')
        Thursday_78.setStyleSheet('font-size:16px;')
        grid.addWidget(Thursday_78, 14, 4, 4, 1)
        Thursday_9 = QTextEdit('')
        Thursday_9.setStyleSheet('font-size:16px;')
        grid.addWidget(Thursday_9, 18, 4, 5, 1)
        '''星期五'''
        Friday_12 = QTextEdit('')
        Friday_12.setStyleSheet('font-size:16px;')
        grid.addWidget(Friday_12, 2, 5, 4, 1)
        Friday_34 = QTextEdit('')
        Friday_34.setStyleSheet('font-size:16px;')
        grid.addWidget(Friday_34, 6, 5, 4, 1)
        Friday_56 = QTextEdit('')
        Friday_56.setStyleSheet('font-size:16px;')
        grid.addWidget(Friday_56, 10, 5, 4, 1)
        Friday_78 = QTextEdit('')
        Friday_78.setStyleSheet('font-size:16px;')
        grid.addWidget(Friday_78, 14, 5, 4, 1)
        Friday_9 = QTextEdit('')
        Friday_9.setStyleSheet('font-size:16px;')
        grid.addWidget(Friday_9, 18, 5, 5, 1)
        '''星期六'''
        Saturday_12 = QTextEdit('')
        Saturday_12.setStyleSheet('font-size:16px;')
        grid.addWidget(Saturday_12, 2, 6, 4, 1)
        Saturday_34 = QTextEdit('')
        Saturday_34.setStyleSheet('font-size:16px;')
        grid.addWidget(Saturday_34, 6, 6, 4, 1)
        Saturday_56 = QTextEdit('')
        Saturday_56.setStyleSheet('font-size:16px;')
        grid.addWidget(Saturday_56, 10, 6, 4, 1)
        Saturday_78 = QTextEdit('')
        Saturday_78.setStyleSheet('font-size:16px;')
        grid.addWidget(Saturday_78, 14, 6, 4, 1)
        Saturday_9 = QTextEdit('')
        Saturday_9.setStyleSheet('font-size:16px;')
        grid.addWidget(Saturday_9, 18, 6, 5, 1)
        '''星期日'''
        Sunday_12 = QTextEdit('')
        Sunday_12.setStyleSheet('font-size:16px;')
        grid.addWidget(Sunday_12, 2, 7, 4, 1)
        Sunday_34 = QTextEdit('')
        Sunday_34.setStyleSheet('font-size:16px;')
        grid.addWidget(Sunday_34, 6, 7, 4, 1)
        Sunday_56 = QTextEdit('')
        Sunday_56.setStyleSheet('font-size:16px;')
        grid.addWidget(Sunday_56, 10, 7, 4, 1)
        Sunday_78 = QTextEdit('')
        Sunday_78.setStyleSheet('font-size:16px;')
        grid.addWidget(Sunday_78, 14, 7, 4, 1)
        Sunday_9 = QTextEdit('')
        Sunday_9.setStyleSheet('font-size:16px;')
        grid.addWidget(Sunday_9, 18, 7, 5, 1)
        widget.setLayout(grid)
        self.setCentralWidget(widget)
if __name__ == '__main__':
    app = QApplication(sys.argv)
    app.setStyleSheet('''
                            QPushButton{background-color: #f0f0f0;}
                            QPushButton:hover{background-color: #f0f0f0;}
                            QPushButton:pressed{background-color: #f0f0f0;}
                        ''')
    main_wnd = CourseTimetable()
    main_wnd.show()
    app.exec()
————————————————

注:课程表中所用的icon再阿里巴巴矢量图标库中可以下载。

相关文章
|
15天前
pyqt6 实现熊猫展览馆
本示例使用 PyQt6 实现了一个展示萌兰、福宝、金虎等大熊猫的界面。通过列表选择不同的大熊猫,界面会显示对应的大熊猫图片。代码包括界面布局、图片展示约束、信号和槽函数的连接,以及完整代码示例。
27 2
|
15天前
pyqt6 添加熊猫案例
本文介绍了如何实现列表的增加、删除和排序功能。通过使用 PyQt6,创建了一个包含输入框和按钮的界面,实现了列表项的动态管理,并提供了详细的代码示例。
29 1
|
6月前
|
存储 算法 C语言
不用看网课就能学到python的文章(第四天)
不用看网课就能学到python的文章(第四天)
高等数学课程介绍目录
高等数学课程介绍目录
179 0
|
人工智能 算法 Java
Python将被加入高考科目?你怎么看?
Python将被加入高考科目?你怎么看?
83 0
|
数据可视化 程序员 数据安全/隐私保护
课程实训QT笔记
链接上一篇没有完的QT笔记
163 1
课程实训QT笔记
|
程序员 Python
黑马程序员-python笔记-从入门到入职
黑马程序员-python笔记-从入门到入职
|
Python
python植物大战僵尸四之添加坚果(学员)
python植物大战僵尸四之添加坚果(学员)
83 0
|
机器学习/深度学习 Python
飞桨学院Python小白逆袭大神练习题第一天
飞桨深度学习学院Python小白逆袭大神练习题oneday 三岁不自量力参加了,哭的分不清东南西北 以下为三岁的答案,与解析,不代表正确!!!
97 0
飞桨学院Python小白逆袭大神练习题第一天
|
机器学习/深度学习 自然语言处理 算法