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__()
self
.setWindowTitle(
"Python "
)
self
.setGeometry(
100
,
100
,
650
,
400
)
self
.UiComponents()
self
.show()
def
UiComponents(
self
):
self
.calendar
=
QCalendarWidget(
self
)
self
.calendar.setGeometry(
50
,
10
,
400
,
250
)
self
.calendar.setCursor(Qt.PointingHandCursor)
self
.calendar.grabKeyboard()
def
keyPressEvent(
self
, e):
keylist
=
[Qt.Key_J, Qt.Key_F, Qt.Key_M, Qt.Key_A, Qt.Key_M, Qt.Key_J,
Qt.Key_J, Qt.Key_A, Qt.Key_S, Qt.Key_O, Qt.Key_N, Qt.Key_D]
month
=
self
.calendar.monthShown()
year
=
self
.calendar.yearShown()
if
e.key()
=
=
keylist[
0
]:
print
(
"J Key Pressed"
)
if
month
=
=
1
:
self
.calendar.setCurrentPage(year,
6
)
elif
month
=
=
6
:
self
.calendar.setCurrentPage(year,
7
)
else
:
self
.calendar.setCurrentPage(year,
1
)
elif
e.key()
=
=
keylist[
2
]:
print
(
"M key pressed"
)
if
month
=
=
3
:
self
.calendar.setCurrentPage(year,
5
)
else
:
self
.calendar.setCurrentPage(year,
3
)
elif
e.key()
=
=
keylist[
3
]:
print
(
"A key pressed"
)
if
month
=
=
4
:
self
.calendar.setCurrentPage(year,
8
)
else
:
self
.calendar.setCurrentPage(year,
4
)
elif
e.key()
in
keylist:
index
=
keylist.index(e.key())
print
(
str
(index
+
1
)
+
" Month Key Pressed"
)
self
.calendar.setCurrentPage(year, index
+
1
)
App
=
QApplication(sys.argv)
window
=
Window()
sys.exit(App.
exec
())