import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
class demoQClalendar(QWidget):
def __init__(self):
super(demoQClalendar, self).__init__()
self.initUI()
def initUI(self):
self.cal = QCalendarWidget(self)
self.cal.setMinimumDate(QDate(1980,1,1))
self.cal.setMaximumDate(QDate(3000,1,1))
self.cal.setGridVisible(True)
self.cal.move(20,20)
self.cal.clicked.connect(self.showDate)
self.lbl = QLabel(self)
#默认为当前系统日期为选中日期
date = self.cal.selectedDate()
self.lbl.setText(date.toString("yyyy-MM-dd dddd"))
self.lbl.move(20, 300)
self.setGeometry(100, 100, 400, 350)
self.setWindowTitle('0432QCalendar')
def showDate(self):
date = self.cal.selectedDate()
print(date.toString())
if __name__ == '__main__':
app = QApplication(sys.argv)
win = demoQClalendar()
win.show()
sys.exit(app.exec_())