Python Make GUI Calendar in Pyside2

In this Python article iam going to show you how to Make GUI Calendar in Pyside2, in this article we are going to use QCalendar class of Pyside2. also you can watch more articles on Python GUI Development with Pyside2 in the below links.

 

1: Getting Started With Pyside2 | Qt For Python 

2: Pyside2 GUI Creating First Window 

3: Pyside2 GUI Creating Window Icon

4: Pyside2 GUI How To Create Icon Modes

5: Pyside2 GUI How To Create Tooltip

6: Pyside2 GUI QPushButton With Signal And Slot

7: Pyside2 GUI Making Center The Window 

8: Python GUI How To Create AboutBox

9: Python GUI How to Create Digital Clock in Pyside2

10: How To Create StatusBar In Pyside2 

11: Pyside2 Creating QProgressBar

12: Pyside2 Layout Managment with QHBoxLayout

13: Pyside2 GridLayout Example

 

 

What is QCalendar ?

 

A QCalendar object maps a year, month, and day-number to a specific day (ultimately identified by its Julian day number), using the rules of a particular system.

The default QCalendar() is a proleptic Gregorian calendar, which has no year zero. Other calendars may be supported by enabling suitable features or loading plugins. Calendars supported as features can be constructed by passing the QCalendar::System enumeration to the constructor. All supported calendars may be constructed by name, once they have been constructed. (Thus plugins instantiate their calendar backend to register it.) Built-in backends, accessible via QCalendar::System, are also always available by name.

 

 

So now this is the complete code for Python Make GUI Calendar in Pyside2

 

 

 

OK in the above code  first we have imported our classes from Pyside2 library

 

 

So now this is our main window class that inherits from QWidgets, and we are going to add some requirements of the window like width, height, title and icon, also we have called our createCalendar() method in this class.

 

 

 

And this is the method that we are going to create our QCalendar, first we have created the object of QVBoxLayout, because we are going to add our Calendar in this VBoxLayout. after that we have created the object of QCalendar and also we have used the grid for our Calendar by using this method to true self.calendar.setGridVisible(True), and at the end we have added our calendar to VBoxLayout.

 

 

 

Also every Pyside2 application must create an application object. The sys.argv parameter is a list of arguments from a command line.

Python scripts can be run from the shell. It is a way how we can control the startup of our scripts.

 

 

 

Finally, we enter the mainloop of the application. The event handling starts from this point. The mainloop receives events from the window system and dispatches them to the application widgets. The mainloop ends if we call the exit() method or the main widget is destroyed. The sys.exit() method ensures a clean exit. The environment will be informed how the application ended.

The exec_() method has an underscore. It is because the exec is a Python keyword. And thus, exec_() was used instead

 

 

 

So now run the complete code and this will be the result

 

Python Make GUI Calendar in Pyside2
Python Make GUI Calendar in Pyside2

 

 

 

Also you can watch the complete video for this article

 

 

 

Subscribe and Get Free Video Courses & Articles in your Email

 

Share via
Copy link
Powered by Social Snap
×