from
PyQt5.QtWidgets
import
*
from
PyQt5
import
QtCore, QtGui
from
PyQt5.QtGui
import
*
from
PyQt5.QtCore
import
*
import
datetime
import
sys
class
Window(QMainWindow):
def
__init__(
self
):
super
().__init__()
self
.setWindowTitle(
"Python "
)
self
.w_width
=
400
self
.w_height
=
530
self
.setGeometry(
100
,
100
,
self
.w_width,
self
.w_height)
self
.UiComponents()
self
.show()
def
UiComponents(
self
):
head
=
QLabel(
"+/- Days from a date Calculator"
,
self
)
head.setWordWrap(
True
)
head.setGeometry(
0
,
10
,
400
,
60
)
font
=
QFont(
'Times'
,
15
)
font.setBold(
True
)
font.setItalic(
True
)
font.setUnderline(
True
)
head.setFont(font)
head.setAlignment(Qt.AlignCenter)
color
=
QGraphicsColorizeEffect(
self
)
color.setColor(Qt.darkCyan)
head.setGraphicsEffect(color)
b_label
=
QLabel(
"Select Date"
,
self
)
b_label.setAlignment(Qt.AlignCenter)
b_label.setGeometry(
50
,
100
,
300
,
20
)
b_label.setStyleSheet(
"QLabel"
"{"
"border : 1px solid black;"
"background : rgba(70, 70, 70, 25);"
"}"
)
b_label.setFont(QFont(
'Times'
,
9
))
self
.calendar
=
QCalendarWidget(
self
)
self
.calendar.setGeometry(
50
,
120
,
300
,
180
)
self
.calendar.setFont(QFont(
'Times'
,
6
))
days_label
=
QLabel(
"Days"
,
self
)
days_label.setGeometry(
50
,
320
,
147
,
40
)
days_label.setAlignment(Qt.AlignCenter)
days_label.setStyleSheet(
"QLabel"
"{"
"border : 2px solid black;"
"background : rgba(70, 70, 70, 35);"
"}"
)
days_label.setFont(QFont(
'Times'
,
9
))
self
.days
=
QSpinBox(
self
)
self
.days.setGeometry(
203
,
320
,
147
,
40
)
self
.days.setMaximum(
99999999
)
self
.days.setFont(QFont(
'Times'
,
9
))
self
.days.setAlignment(Qt.AlignCenter)
add
=
QPushButton(
"Add Days"
,
self
)
add.setGeometry(
80
,
380
,
100
,
40
)
add.clicked.connect(
self
.add_action)
color
=
QGraphicsColorizeEffect()
color.setColor(Qt.blue)
add.setGraphicsEffect(color)
subtract
=
QPushButton(
"Subtract Days"
,
self
)
subtract.setGeometry(
220
,
380
,
100
,
40
)
subtract.clicked.connect(
self
.subtract_action)
color
=
QGraphicsColorizeEffect()
color.setColor(Qt.red)
subtract.setGraphicsEffect(color)
self
.result
=
QLabel(
self
)
self
.result.setAlignment(Qt.AlignCenter)
self
.result.setGeometry(
50
,
440
,
300
,
60
)
self
.result.setWordWrap(
True
)
self
.result.setStyleSheet(
"QLabel"
"{"
"border : 3px solid black;"
"background : white;"
"}"
)
self
.result.setFont(QFont(
'Arial'
,
11
))
def
add_action(
self
):
days
=
self
.days.value()
self
.calculate(days)
def
subtract_action(
self
):
days
=
0
-
self
.days.value()
self
.calculate(days)
def
calculate(
self
, days):
selected_date
=
self
.calendar.selectedDate()
new_date
=
selected_date.addDays(days)
self
.result.setText(
"Date : "
+
new_date.toString(Qt.ISODate))
App
=
QApplication(sys.argv)
window
=
Window()
sys.exit(App.
exec
())