I have a problem. I want to get a selected date in the format 2021-12-12 from the PyQt calendar. I can print out the variable date (commented) in the get_date function but I could not access this variable from outside. So I created the time variable and wanted to overwrite the variable through the function, but when I try to print out time after the code I get "None".
Do you have any recommendations?
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtCore import QDate, QTime, QDateTime, Qt
import sys
app = QtWidgets.QApplication(sys.argv)
window = QtWidgets.QWidget()
window.setWindowTitle("Datumsauswahl")
cal = QtWidgets.QCalendarWidget(gridVisible=True)
lay = QtWidgets.QVBoxLayout(window)
lay.addWidget(cal)
time = datetime.datetime.now()
@QtCore.pyqtSlot(QtCore.QDate)
def get_date(date): # <--- date parameter
date = date.toString(Qt.ISODate)
#print(date)
time = date
#time = get_date(date)
time = cal.clicked.connect(get_date)
window.show()
print(time)
sys.exit(app.exec())
print(time)