
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
import sys from PyQt5.QtWidgets import QApplication, QWidget, QLineEdit, QPushButton, QVBoxLayout, QLabel class Formulario(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): self.label_nombre = QLabel('Nombre:', self) self.text_nombre = QLineEdit(self) self.label_edad = QLabel('Edad:', self) self.text_edad = QLineEdit(self) self.boton_enviar = QPushButton('Enviar', self) self.boton_enviar.clicked.connect(self.enviar_datos) layout = QVBoxLayout() layout.addWidget(self.label_nombre) layout.addWidget(self.text_nombre) layout.addWidget(self.label_edad) layout.addWidget(self.text_edad) layout.addWidget(self.boton_enviar) self.setLayout(layout) self.setWindowTitle('Formulario con PyQt5') def enviar_datos(self): nombre = self.text_nombre.text() edad = self.text_edad.text() print(f"Nombre: {nombre}, Edad: {edad}") app = QApplication(sys.argv) form = Formulario() form.show() sys.exit(app.exec_()) |