1 # -*- coding:utf-8 -*- 2 ''' 3 Created on Sep 20, 2018 4 5 @author: SaShuangYiBing 6 7 Comment: 8 ''' 9 import sys 10 from PyQt5.QtCore import QDate 11 from PyQt5.QtWidgets import QApplication,QWidget,QLabel,QCalendarWidget 12 13 class New_test(QWidget): 14 def __init__(self): 15 super().__init__() 16 self.initUI() 17 18 def initUI(self): 19 cal = QCalendarWidget(self) 20 cal.setGridVisible(True) 21 cal.move(10,7) 22 cal.clicked.connect(self.showDate) 23 24 self.label = QLabel(self) 25 date = cal.selectedDate() 26 self.label.setText(date.toString()) 27 self.label.move(90,220) 28 29 self.setGeometry(300,300,280,250) 30 self.setWindowTitle('QCalendar') 31 self.show() 32 33 def showDate(self,date): 34 self.label.setText(date.toString()) 35 36 if __name__ == '__main__': 37 app = QApplication(sys.argv) 38 ex = New_test() 39 sys.exit(app.exec_())