I have a question about PyQt5. I try to have a date input, so that the user presses a box and opens a calendar to select the date.
In some places I have read about the code setCalendarPopup(true)
, but I have not been able to use it successfully.
What I want is that when I click on a QlineEdit ( fin_entry
in my code) a calendar opens ( cal
in my code).
I attach my code:
import sys
from PyQt5.QtWidgets import QMainWindow, QAction, qApp, QApplication,QLineEdit,QInputDialog,QFileDialog,QComboBox,QSpinBox,QDateEdit,QCalendarWidget,QLabel
from PyQt5.QtGui import QIcon
class ventana(QMainWindow):
def __init__(self):
super().__init__()
self.nombre_ventana = "valorizador"
self.ventana_izquierda = 100
self.ventana_arriba = 100
self.ventana_ancho=1440
self.ventana_alto = 900
self.initUI()
def initUI(self):
self.setGeometry(self.ventana_izquierda,self.ventana_arriba,self.ventana_ancho,self.ventana_alto)
self.setWindowTitle(self.nombre_ventana)
menu=self.menuBar()
archivo=menu.addMenu("Archivo")
boton_guardar=QAction("Guardar",self)
etiqueta_tasa= QLabel("Tasa Fija %",self)
etiqueta_tasa.move(50,100)
tasa_entry = QLineEdit(self)
tasa_entry.setInputMask("9,99")
tasa_entry.move(150, 100)
etiqueta_moneda = QLabel("Moneda", self)
etiqueta_moneda.move(50,150)
moneda_combobox=QComboBox(self)
valores_moneda=["USD","Otra"]
moneda_combobox.move(150,150)
for i in valores_moneda:
moneda_combobox.addItem(i)
etiqueta_fincontrato = QLabel("Fecha vencimiento", self)
etiqueta_fincontrato.move(50, 250)
fin_entry = QLineEdit(self)
cal = QCalendarWidget(self) #aquì no se como agregarlo dentro del QlineEdit
cal.move(400,400)
fin_entry.setInputMask("99-99-9999")
fin_entry.move(150, 250)
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = ventana()
sys.exit(app.exec_())