import sys from PyQt4 import QtGui class Example(QtGui.QWidget): def __init__(self): super(Example, self).__init__() self.initUI() def initUI(self): cal = QtGui.QCalendarWidget(self) cal.setGridVisible(True) vbox = QtGui.QVBoxLayout() vbox.addWidget(cal) self.setLayout(vbox) self.setGeometry(300, 300, 350, 300) self.setWindowTitle('Calendar') self.show() def main(): app = QtGui.QApplication(sys.argv) ex = Example() sys.exit(app.exec_()) if __name__ == '__main__': main()
import sys from PyQt4 import QtGui, QtCore class Example(QtGui.QMainWindow): def __init__(self): super(Example, self).__init__() self.initUI() def initUI(self): self.statusBar().showMessage('Select a date') cal = QtGui.QCalendarWidget(self) cal.clicked[QtCore.QDate].connect(self.showDate) self.setCentralWidget(cal) self.setGeometry(300, 300, 350, 300) self.setWindowTitle('Calendar') self.show() def showDate(self, date): self.statusBar().showMessage(date.toString()) def main(): app = QtGui.QApplication(sys.argv) ex = Example() sys.exit(app.exec_()) if __name__ == '__main__': main()In summary, the PyQt4.QtGui.QCalendarWidget is a widget used to display a calendar in PyQt4. It can be used in various contexts, such as in simple examples or as part of a dialog window. It is part of the QtGui package library.