PDA

View Full Version : line edit data input



BrianBrian
6th May 2015, 01:48
Hi, i would love a little direction here please as i have been searching but not finding a solution to my issue.
What i would love is to take the data i enter into the line edit field of my gui and send that data to a string in my list. In the case below it is the value at ls[0] that i want to change to the value i enter in the gui line edit field. (not using line edit_2 at the moment) Am i going about it the wrong way?


from PyQt4 import QtCore, QtGui
import sys

ls = ["a", "b"]

try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s

try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)

class Ui_Dialog(QtGui.QWidget):
def __init__(self):
QtGui.QWidget.__init__(self)
self.setupUi(self)
def setupUi(self, Dialog):
Dialog.setObjectName(_fromUtf8("Dialog"))
Dialog.resize(400, 300)
self.pushButton = QtGui.QPushButton(Dialog)
self.pushButton.setGeometry(QtCore.QRect(30, 40, 75, 23))
self.pushButton.setObjectName(_fromUtf8("pushButton"))
self.lineEdit = QtGui.QLineEdit(Dialog)
self.lineEdit.setGeometry(QtCore.QRect(120, 40, 113, 20))
self.lineEdit.setObjectName(_fromUtf8("lineEdit"))
self.lineEdit_2 = QtGui.QLineEdit(Dialog)
self.lineEdit_2.setGeometry(QtCore.QRect(260, 40, 113, 20))
self.lineEdit_2.setObjectName(_fromUtf8("lineEdit_2"))

self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)

def retranslateUi(self, Dialog):
Dialog.setWindowTitle(_translate("Dialog", "Dialog", None))
self.pushButton.setText(_translate("Dialog", "PushButton", None))
self.pushButton.clicked.connect(self.changedata)


def changedata(self):
print ls[0] #this line is just to print out what ls[0] is before it is changed
ls[0] = self.lineEdit #this is where i am stuck as i do not know how to get the line edit data. i,m new to python and qt so forgive me if i'm a bit off
print ls[0] #this line is to print out the new value of ls[0] to see if it changed


if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
ex = Ui_Dialog()
ex.show()
sys.exit(app.exec_())

BrianBrian
6th May 2015, 04:46
figured it out... line 48 ls[0] = self.lineEdit.text()

Thanks anyway.....

d_stranz
6th May 2015, 17:22
Glad we could help :D