Jul-21-2018, 02:53 PM
from PyQt5.QtGui import * from PyQt5.QtWidgets import * import sys def btnAdd_pressed(): # setItem(row,column,content) tablEx.setItem(0, 0, QTableWidgetItem(LinEd1.text())) tablEx.setItem(0, 1, QTableWidgetItem(LinEd2.text())) if RadioM.isChecked(): tablEx.setItem(0, 2, QTableWidgetItem('Male')) elif RadioF.isChecked(): tablEx.setItem(0, 2, QTableWidgetItem('Female')) else: tablEx.setItem(0, 2, QTableWidgetItem('None')) app = QApplication(sys.argv) window = QWidget() window.setGeometry(350, 150, 600, 450) window.setWindowTitle('Table') window.setToolTip('This program is not complete') Lable1 = QLabel('Full Name :', window) Lable1.move(40, 15) Lable1 = QLabel('Age :', window) Lable1.move(252, 15) Lable1 = QLabel('Gender :', window) Lable1.move(380, 15) btnAdd = QPushButton('Add', window) btnAdd.resize(80, 30) btnAdd.move(500, 40) # Add an action for the button click btnAdd.clicked.connect(btnAdd_pressed) LinEd1 = QLineEdit('', window) # Name Line Edit LinEd1.resize(200, 30) LinEd1.move(40, 40) LinEd2 = QLineEdit('', window) # Age Line Edit LinEd2.resize(100, 30) LinEd2.move(250, 40) RadioM = QRadioButton('Male', window) # Gender Radio Buttons RadioM.move(370, 35) RadioF = QRadioButton('Female', window) # Gender Radio Buttons RadioF.move(370, 55) tablEx = QTableWidget(window) tablEx.resize(540, 300) tablEx.move(30, 100) tablEx.setColumnCount(3) tablEx.setRowCount(9) tablEx.setHorizontalHeaderLabels(("Name,Age,Gender").split(',')) window.show() app.exec_()Now you have to think about a way to increment the
row
when btnAdd_pressed()
is called.