import sys
from PyQt4 import QtGui, QtCore
class DataApp(QtGui.QWidget):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.setGeometry(200, 100, 400, 300);
self.setWindowTitle('Data App')
self.setWindowIcon(QtGui.QIcon('e.png'))
self.lName = QtGui.QLabel('Name', self)
self.lCity = QtGui.QLabel('City', self)
self.leName = QtGui.QLineEdit(self)
self.leCity = QtGui.QLineEdit(self)
self.pbAdd = QtGui.QPushButton('Add', self)
self.lsName = QtGui.QLabel('Name', self)
self.lsCity = QtGui.QLabel('City', self)
self.lsNo = QtGui.QLabel('No', self)
self.col1 = 10
self.row1 = 10
self.width = 150
self.height = 20
self.hozSpace = 10
self.verSpace = 10
self.col2 = self.col1 + self.width + self.hozSpace
self.col3 = self.col1 + 2*(self.width + self.hozSpace)
self.row2 = self.row1 + self.height + self.verSpace
self.row3 = self.row1 + 2*(self.height + self.verSpace)
self.lName.setGeometry(self.col1, self.row1, self.width, self.height)
self.lCity.setGeometry(self.col2, self.row1, self.width, self.height)
self.leName.setGeometry(self.col1, self.row2, self.width, self.height)
self.leCity.setGeometry(self.col2, self.row2, self.width, self.height)
self.pbAdd.setGeometry(self.col3, self.row2, self.width-81, self.height)
self.colS1 = 10
self.colS2 = self.colS1 + 30
self.colS3 = self.colS1 + 30 + 150
self.lsNo.setGeometry(self.colS1, self.row3, self.width, self.height)
self.lsName.setGeometry(self.colS2, self.row3, self.width, self.height)
self.lsCity.setGeometry(self.colS3, self.row3, self.width, self.height)
self.connect(self.pbAdd, QtCore.SIGNAL('clicked()'), self.addData)
self.n = 0;
len = 5
self.no = [QtGui.QLabel('', self) for i in range(len)]
self.name = [QtGui.QLabel('', self) for i in range(len)]
self.city = [QtGui.QLabel('', self) for i in range(len)]
def addData(self):
try:
self.no[self.n].setText(str(self.n + 1))
self.name[self.n].setText(self.leName.text())
self.city[self.n].setText(self.leCity.text())
row = 90 + (20 * self.n)
self.no[self.n].setGeometry(self.colS1, row, self.width, self.height)
self.name[self.n].setGeometry(self.colS2, row, self.width, self.height)
self.city[self.n].setGeometry(self.colS3, row, self.width, self.height)
self.n = self.n + 1
except IndexError:
QtGui.QMessageBox.information(self, 'Maximum Capacity', "The List Is Maximum", QtGui.QMessageBox.Ok)
app = QtGui.QApplication(sys.argv)
one = DataApp()
one.show()
sys.exit(app.exec_())
from PyQt4 import QtGui, QtCore
class DataApp(QtGui.QWidget):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.setGeometry(200, 100, 400, 300);
self.setWindowTitle('Data App')
self.setWindowIcon(QtGui.QIcon('e.png'))
self.lName = QtGui.QLabel('Name', self)
self.lCity = QtGui.QLabel('City', self)
self.leName = QtGui.QLineEdit(self)
self.leCity = QtGui.QLineEdit(self)
self.pbAdd = QtGui.QPushButton('Add', self)
self.lsName = QtGui.QLabel('Name', self)
self.lsCity = QtGui.QLabel('City', self)
self.lsNo = QtGui.QLabel('No', self)
self.col1 = 10
self.row1 = 10
self.width = 150
self.height = 20
self.hozSpace = 10
self.verSpace = 10
self.col2 = self.col1 + self.width + self.hozSpace
self.col3 = self.col1 + 2*(self.width + self.hozSpace)
self.row2 = self.row1 + self.height + self.verSpace
self.row3 = self.row1 + 2*(self.height + self.verSpace)
self.lName.setGeometry(self.col1, self.row1, self.width, self.height)
self.lCity.setGeometry(self.col2, self.row1, self.width, self.height)
self.leName.setGeometry(self.col1, self.row2, self.width, self.height)
self.leCity.setGeometry(self.col2, self.row2, self.width, self.height)
self.pbAdd.setGeometry(self.col3, self.row2, self.width-81, self.height)
self.colS1 = 10
self.colS2 = self.colS1 + 30
self.colS3 = self.colS1 + 30 + 150
self.lsNo.setGeometry(self.colS1, self.row3, self.width, self.height)
self.lsName.setGeometry(self.colS2, self.row3, self.width, self.height)
self.lsCity.setGeometry(self.colS3, self.row3, self.width, self.height)
self.connect(self.pbAdd, QtCore.SIGNAL('clicked()'), self.addData)
self.n = 0;
len = 5
self.no = [QtGui.QLabel('', self) for i in range(len)]
self.name = [QtGui.QLabel('', self) for i in range(len)]
self.city = [QtGui.QLabel('', self) for i in range(len)]
def addData(self):
try:
self.no[self.n].setText(str(self.n + 1))
self.name[self.n].setText(self.leName.text())
self.city[self.n].setText(self.leCity.text())
row = 90 + (20 * self.n)
self.no[self.n].setGeometry(self.colS1, row, self.width, self.height)
self.name[self.n].setGeometry(self.colS2, row, self.width, self.height)
self.city[self.n].setGeometry(self.colS3, row, self.width, self.height)
self.n = self.n + 1
except IndexError:
QtGui.QMessageBox.information(self, 'Maximum Capacity', "The List Is Maximum", QtGui.QMessageBox.Ok)
app = QtGui.QApplication(sys.argv)
one = DataApp()
one.show()
sys.exit(app.exec_())
No comments:
Post a Comment