from datetime import datetime from PyQt5.QtGui import QFont from PyQt5.QtWidgets import * class HeadLabel(QLabel): def __init__(self): super(HeadLabel, self).__init__() self.setObjectName('head_label') layout = QVBoxLayout() # self.resize(200,100) # widget = QWidget(self) # widget.setLayout(layout) # self.setMinimumHeight(300) # self.setMinimumWidth(300) # widget.setMaximumHeight(100) # 设置当前时间 weekday = ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"] weekday_index = datetime.now().weekday() month = datetime.now().month day = datetime.now().day # 输出日期示例 # print(str(month) + '月' + str(day) + '日,' + weekday[weekday_index]) self.title = QLabel("我的一天") # 设置字体大小 self.font = QFont() self.font.setPointSize(32) self.title.setFont(self.font) self.title.setObjectName('title') self.time_label = QLabel(str(month) + '月' + str(day) + '日,' + weekday[weekday_index]) self.time_label.setObjectName('time_label') layout.addWidget(self.title) layout.addWidget(self.time_label) self.setLayout(layout) self.show()