In this lesson we will create a Months menu with menu items from January to December. The most important take away in this lesson is learning how to create toggleable mean items, which gives you more control of your application.

Buy Me a Coffee? Your support is much appreciated!
PayPal Me:
Venmo: @Jie-Jenn

Source Code

import sys
import calendar
from PyQt5.QtWidgets import QApplication, QMainWindow, QAction

class AppDemo(QMainWindow):
    def __init__(self):
        self.resize(500, 500)

        menuMonths = self.menuBar().addMenu('Months')

        for i in range(1, 13):
            action = menuMonths.addAction(calendar.month_name[i])

    def printValue(self, action):
        print('{0}-{1}'.format(action.text(), action.isChecked()))

app = QApplication(sys.argv)        

demo = AppDemo()