PyQt5 Calendar 控件使用示例
# Time: 2021/06/30
#Author: Xiaohong
# 运行环境: OS: Windows 7
# Python: 3.7
# 功能: PyQt5 Calendar 控件
界面效果如下:
源代码如下:
from PyQt5.QtWidgets import QWidget,QCalendarWidget,QLabel,QApplication,QVBoxLayout
from PyQt5.QtCore import QDate
import sys
class CalendarWidget(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
vbox = QVBoxLayout(self)
cal = QCalendarWidget(self)
cal.setGridVisible(True)
cal.clicked[QDate].connect(self.showDate)
vbox.addWidget(cal)
date = cal.selectedDate()
self.lbl = QLabel(self)
self.lbl.setText(date.toString())
vbox.addWidget(self.lbl)