pyqt-todolist/view/MyDayHeadLabel.py

41 lines
1.4 KiB
Python

from datetime import datetime
from PyQt5.QtGui import QFont
from PyQt5.QtWidgets import *
class HeadLabel(QLabel):
def __init__(self):
super(HeadLabel, self).__init__()
self.setScaledContents(True)
self.setObjectName('head_label')
layout = QVBoxLayout()
# self.setMinimumHeight(170)
# 设置当前时间
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.title.setStyleSheet('font-weight:bold;color:white;margin:0px')
# self.title.setObjectName('title')
# 设置字体大小
self.font = QFont()
self.font.setPointSize(26)
self.title.setFont(self.font)
# todo: 需要调整布局,修复字体间距
# self.title.setObjectName('title')
self.time_label = QLabel(str(month) + '' + str(day) + '日,' + weekday[weekday_index])
self.time_label.setStyleSheet('color:white;margin:0px')
# self.time_label.setObjectName('time_label')
layout.addWidget(self.title)
layout.addWidget(self.time_label)
self.setLayout(layout)
self.show()