-1

I'm a beginner in PyQt and I made a FORMULAR. self.tName1, self.tlName1, self.tCel, self.tCel1,self.tcc1, self.tEmail, self.tTel are QLineEdit and I put all these variables in a list. Then, I made a for loop in order to evaluate each QLineEdit value and fill them if they are empty with 'NULL'. The loop works well but I'm trying to print all the values inside the list. For example: ['NULL','NULL','3176797100','NULL','NULL','1098685161','mm@gmail.com', 'NULL'] but it doesn't work.

self.tName1 = QtGui.QLineEdit(self)
self.tName1.move(85,176) 
self.tName1.resize(199,30)

self.tlName1 = QtGui.QLineEdit(self)
self.tlName1.move(95,210) 
self.tlName1.resize(190,30)

def eval(self):

    var=[self.tName1, self.tlName1, self.tCel, self.tCel1,self.tcc1, self.tEmail, self.tTel]
    i=0
    for i in  range(len(var)):
        if var[i]=="":
            var[i]='NULL'
        else:
           pass

    print var
    print self.tName1.text() 
    print self.tName1

If I print self.variable.text() nothing appears. On the other hand, if I print self.Name1 appears he posotion of the QLineEdit: <PyQt4.QtGui.QLineEdit object at 0x7fb1046cc180>. I appreciate your help!! :P

Margarita Gonzalez
  • 1,127
  • 7
  • 20
  • 39
  • when you give -1 to a question explain in a comment why. @Margarita Gonzalez please give the complete code, it is not clear how are self.tname1 is a PyQt4.QtGui.QLineEdit object and you try to access it as a string. – Ammar Oct 23 '14 at 15:28

1 Answers1

-1

Well, the question is not so clear, this line:

var=[self.tName1, self.tlName1, self.tCel, self.tCel1,self.tcc1, self.tEmail, self.tTel]

creates a new list contains some variables, and whatever you change in this list, it does not affect the values of the original variables, have a look:

>>> a = "hello"
>>> b = "world"
>>> var = [a, b]
>>> var 
["hello", "world"]
>>> var[0] = "hi"
>>> a
hello
>>> var
["hi", "world"]
>>> a = "whatsup"
>>> var
["hi", "world"]

so if you want to change the original variable( in your case self.tname1.text, self.tCel.text) you have to change each one of them individually, I think it is done with:

>>> if self.tname1.text()=="": 
....    self.tname1.setText("NULL")

and so on.

I hope this answer something to you.

Edit: after the comment, to obtain the text attribute from an object you can try this:

print [x.text() for x in var]
Ammar
  • 1,305
  • 2
  • 11
  • 16
  • I know that and how it works!! I don't know why I can not see the list values? only this[, , , , , , ] – Margarita Gonzalez Oct 23 '14 at 16:21
  • You just print the list so you get the representation of the contained elements. Loop over the list for yourself, get the desired attribute value from the `PyQt4.QtGui.QLineEdit` object and print it. – Matthias Oct 23 '14 at 17:21