<p>尝试:</p>
<pre><code>import sys
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
class MyWin(QWidget):
def __init__(self):
super().__init__()
lblCurrentDateTime = QLabel()
self.lblDateTimeEdit = QLabel()
btn = QPushButton("DateTime + 7 days")
btn.clicked.connect(self.editDateDay)
lblCurrentDateTime.setText(QDateTime.currentDateTime().toString('yyyy MM dd hh:mm:ss'))
self.dateTimeBegin = QDateTimeEdit()
self.dt = self.dateTimeBegin.dateTime().currentDateTime()
lay = QVBoxLayout(self)
lay.addWidget(lblCurrentDateTime)
lay.addWidget(self.lblDateTimeEdit)
lay.addWidget(btn)
def editDateDay(self):
self.dateTimeBegin.setDateTime(self.dt.addDays(7))
self.dt = self.dt.addDays(7)
currentTime = self.dateTimeBegin.dateTime().toString('yyyy MM dd hh:mm:ss')
self.lblDateTimeEdit.setText(self.dateTimeBegin.dateTime().toString('yyyy MM dd hh:mm:ss'))
if __name__ =="__main__":
qapp = QApplication(sys.argv)
w = MyWin()
w.show()
sys.exit(qapp.exec())
</code></pre>
<p><a href="https://i.stack.imgur.com/tHrgm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tHrgm.png" alt="enter image description here"/></a></p>