Open In App

PyQt5 QCalendarWidget – Showing today date

Last Updated : 09 Aug, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will see how we can show today’s date in the QCalendarWidget to the screen. Showing today’s date means to show the present date i.e day month and year irrespective of the selected date or at which page the calendar is currently. By default, the calendar shows the today’s date.

In order to do this we will use showToday method with the QCalendarWidget object.
Syntax : calendar.showToday()
Argument : It takes no argument
Return : It returns None 

Below is the implementation 

Python3




# importing libraries
from PyQt5.QtWidgets import *
from PyQt5 import QtCore, QtGui
from PyQt5.QtGui import *
from PyQt5.QtCore import *
import sys
 
 
class Window(QMainWindow):
 
    def __init__(self):
        super().__init__()
 
        # setting title
        self.setWindowTitle("Python ")
 
        # setting geometry
        self.setGeometry(100, 100, 600, 400)
 
        # calling method
        self.UiComponents()
 
        # showing all the widgets
        self.show()
 
    # method for components
    def UiComponents(self):
 
        # creating a QCalendarWidget object
        calendar = QCalendarWidget(self)
 
        # setting geometry to the calendar
        calendar.setGeometry(10, 10, 400, 250)
 
        # creating push button
        push = QPushButton("Today", self)
 
        # setting geometry to the push
        push.setGeometry(120, 280, 100, 40)
 
        # adding action to the push
        push.clicked.connect(lambda: do_action())
 
        def do_action():
            # showing the today's date
            calendar.showToday()
 
 
 
 
# create pyqt5 app
App = QApplication(sys.argv)
 
# create the instance of our Window
window = Window()
 
# start the app
sys.exit(App.exec())


Output : 

 



Similar Reads

PyQt5 QCalendarWidget - Showing Selected Date
In this article we will see how we can show the date of the QCalendarWidget to the screen. Showing the selected date will change the page if year and month are different. User can select the date with the help of mouse or keyboard and programmatically it can be set with the help of setSelectedDate method. In order to do this we will use showSelecte
2 min read
PyQt5 QCalendarWidget - Showing it
In this article we will see how we can show the QCalendarWidget to the screen irrespective its current state is hidden. Showing the QCalendarWidget changes the visible property and set it to true. In order to do this we will use show method with the QCalendarWidget object.Syntax : calendar.show()Argument : It takes no argumentReturn : It returns No
2 min read
PyQt5 QCalendarWidget - Showing Next Month
In this article we will see how we can show the next month of the QCalendarWidget to the screen. Showing the next month means the next month relative to the currently displayed month. Note : The selected date is not changed. In order to do this we will use showNextMonth method with the QCalendarWidget object.Syntax : calendar.showNextMonth()Argumen
2 min read
PyQt5 QCalendarWidget - Showing Next Year
In this article we will see how we can show the next year of the QCalendarWidget to the screen. Showing the next year means the next year relative to the currently displayed year. Note : The selected date is not changed. In order to do this we will use showNextYear method with the QCalendarWidget object.Syntax : calendar.showNextYear()Argument : It
2 min read
PyQt5 QCalendarWidget - Showing Previous Year
In this article we will see how we can show the previous year of the QCalendarWidget to the screen. Showing the previous year means the previous year relative to the currently displayed year. Note : The selected date is not changed. In order to do this we will use showPreviousYear method with the QCalendarWidget object.Syntax : calendar.showPreviou
2 min read
PyQt5 QCalendarWidget - Showing Previous Month
In this article we will see how we can show the previous month of the QCalendarWidget to the screen. Showing the previous month means the previous year relative to the currently displayed month. Note : The selected date is not changed. In order to do this we will use showPreviousMonth method with the QCalendarWidget object.Syntax : calendar.showPre
2 min read
Python | Find yesterday's, today's and tomorrow's date
Prerequisites: datetime module We can handle Data objects by importing the module datetime and timedelta to work with dates. datetime module helps to find the present day by using the now() or today() method.timedelta class from datetime module helps to find the previous day date and next day date.Syntax for timedelta: class datetime.timedelta(days
3 min read
PyQt5 QSpinBox – Showing it on lower level
In this article we will see how we can make the spin box at lower level, lower level means at it will show on the bottom if it collides with some other spin box position, by default when we create two spin box at similar position, the spin box which was created at the end will show on the top although we can change this. In order to do this we will
2 min read
PyQt5 Checkable ComboBox - Showing checked items in textview
In this article we will see how we can show the checked items in the text view(line edit) part of the combo box, we know in order to create the checkable items in the combo box we have to create a class of check-able combo box which inherits the combo box class and add the check-able items, but when we check items only the last item user check is v
3 min read
PyQt5 QSpinBox – Showing it on above level
In this article we will see how we can make the spin box at above level, above level means at it will show on the top if it collides with some other spin box position, by default when we create two spin box at similar position, the spin box which was created at the end will show on the top although we can change this. In order to do this we will us
2 min read