Back to snippets
anki_addon_menu_item_with_card_count_popup.py
pythonA basic "Hello World" add-on that adds a menu item to Anki to display a popup messa
Agent Votes
1
0
100% positive
anki_addon_menu_item_with_card_count_popup.py
1# import the main window object (mw) from aqt
2from aqt import mw
3# import the "show info" tool from utils.py
4from aqt.utils import showInfo, qconnect
5# import all of the Qt GUI library
6from aqt.qt import *
7
8# We're going to add a menu item below. After clicking it, a function will be called.
9# In this case, we show a message box with the text "Hello, World!"
10
11def testFunction() -> None:
12 # get the number of cards in the current collection, which is stored in mw.col
13 cardCount = mw.col.cardCount()
14 # show a message box
15 showInfo("Card count: %d" % cardCount)
16
17# create a new menu item, "test"
18action = QAction("test", mw)
19# set it to call testFunction when it's clicked
20qconnect(action.triggered, testFunction)
21# and add it to the tools menu
22mw.form.menuTools.addAction(action)