1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| import sys from PyQt4.QtCore import * from PyQt4.QtGui import *
class window(QWidget): def __init__(self, parent=None): super(window, self).__init__(parent) self.init()
def init(self): layout = QVBoxLayout() cal = QCalendarWidget() self.label1 = QLabel()
cal.setGridVisible(True) cal.clicked.connect(self.showDate) date = cal.selectedDate() self.label1.setText(date.toString()) cal.move(20,20) self.label1.move(20,200)
layout.addWidget(cal) layout.addWidget(self.label1) self.setLayout(layout) self.setWindowTitle(u"日历")
def showDate(self,date): self.label1.setText(date.toString())
def main(): app = QApplication(sys.argv) ex = window() ex.show() sys.exit(app.exec_())
if __name__ == '__main__': main()
|