PyQt5 QCalendarWidget – Setting Start Timer

In this article we will see how we can set the start timer of the QCalendarWidget. In order to do this we use startTimer method, this method calls the timerEvent after the certain interval is passed. It starts a timer and returns a timer identifier, or returns zero if it could not start a timer.

In order to do this we will use startTimer method with the QCalendarWidget object.

Syntax : calendar.startTimer(milliseconds)

Argument : It takes integer as argument i.e interval time in milliseconds

Return : It return integer

Note : In order to use the startTimer we have to override the timerEvent

Below is the implementation





# importing libraries
from PyQt5.QtWidgets import * 
from PyQt5 import QtCore, QtGui
from PyQt5.QtGui import * 
from PyQt5.QtCore import * 
import sys
# QCalendarWidget Class
class Calendar(QCalendarWidget):
    # constructor
    def __init__(self, parent = None):
        super(Calendar, self).__init__(parent)
    # overriding the timer event
    def timerEvent(self, event):
        # show the next month
class Window(QMainWindow):
    def __init__(self):
        # setting title
        self.setWindowTitle("Python ")
        # setting geometry
        self.setGeometry(100, 100, 650, 400)
        # calling method
        # showing all the widgets
    # method for components
    def UiComponents(self):
        # creating a QCalendarWidget object
        # as Calendar class inherits QCalendarWidget
        self.calendar = Calendar(self)
        # setting geometry to the calender
        self.calendar.setGeometry(50, 10, 400, 250)
        # setting cursor
        # starting the calendar timer
        # passing 1000 milliseconds as parameter
        timer_id = self.calendar.startTimer(1000)
        # creating label to show the properties
        self.label = QLabel(self)
        # setting geometry to the label
        self.label.setGeometry(100, 280, 250, 60)
        # making label multi line
        # setting text to the label
        self.label.setText("Timer ID : " + str(timer_id))
# create pyqt5 app
App = QApplication(sys.argv)
# create the instance of our Window
window = Window()
# start the app


Output :

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.