[Python-mx] Cambiar valor de etiqueta pyqt4

Hiram hiramhzr at gmail.com
Sat Mar 12 20:54:50 EST 2016


Perfecto, muchas gracias.

El sáb., 12 de mar. de 2016 a la(s) 14:20, Noe Nieto <nnieto at noenieto.com>
escribió:

> Ahí tienes.
>
>
>
> #!/usr/bin/python
> # -*- coding: utf-8 -*-
>
> import sys
> from PyQt4 import QtGui
> import time
> import threading
> from datetime import datetime
>
> class MyThread(threading.Thread):
>     def __init__(self, app_instace):
>         threading.Thread.__init__(self)
>         self.app_instace = app_instace
>
>     def run(self):
>         while(True):
>             self.app_instace.saludar()
>             time.sleep(5)
>
> class MyQtApp(QtGui.QMainWindow):
>     def __init__(self):
>         super(MyQtApp, self).__init__()
>         self.initGui()
>         self.counter = 0
>         self.cntr_thread = MyThread(self)
>         self.cntr_thread.daemon = True
>         self.cntr_thread.start()
>
>
>     def initGui(self):
>         self.saludo = QtGui.QLabel('Cambio:', self)
>         self.saludo.resize(self.width(), 50)
>         self.saludo.move(120, 10)
>
>         self.lBD = QtGui.QLabel('1', self)
>         self.lBD.resize(self.width(), 50)
>         self.lBD.move(145, 80)
>
>         self.setGeometry(300, 300, 300, 160)
>         self.setWindowTitle('Cambio valor de etiqueta')
>         self.show()
>
>     def saludar(self):
>         self.lBD.setText(
>             '%s    Hola: %i' %
>             (datetime.now().strftime('%X'), self.counter)
>         )
>         self.counter += 1
>
>
> def main():
>     app = QtGui.QApplication(sys.argv)
>     ex = MyQtApp()
>
>     sys.exit(app.exec_())
>
> if __name__ == '__main__':
>     main()
>
> --
> Noe
>
> 2016-03-12 11:30 GMT-08:00 Hiram <hiramhzr at gmail.com>:
>
>> Hola buenas tardes, estoy intentando cambiar el valor de una etiqueta en
>> tiempo de ejecución cada "n" tiempo, acá pongo un ejemplo lo que intento
>> hacer hasta ahora con este código me tira el siguiente error: "AttributeError:
>> 'function' object has no attribute 'lBD'"
>>
>> Dejo el código:
>>
>> #!/usr/bin/python
>> # -*- coding: utf-8 -*-
>>
>> import sys
>> from PyQt4 import QtGui
>> from PyQt4 import QtCore
>> import time
>> import threading
>>
>> class leerSubidas(threading.Thread):
>>     def __init__(self, parent):
>>         threading.Thread.__init__(self)
>>         self.parent = parent
>>
>>     def run(self):
>>         while(True):
>>             self.parent.saludar()
>>             time.sleep(5)
>>
>> class init(QtGui.QMainWindow):
>>     def __init__(self):
>>         super(init, self).__init__()
>>         self.upCount = leerSubidas(self)
>>         self.upCount.daemon = True
>>         self.upCount.start()
>>         self.initGui()
>>
>>     def initGui(self):
>>         self.saludo = QtGui.QLabel('Cambio:', self)
>>         self.saludo.resize(self.width(), 50)
>>         self.saludo.move(120, 10)
>>
>>         self.lBD = QtGui.QLabel('1', self)
>>         self.lBD.resize(self.width(), 50)
>>         self.lBD.move(145, 80)
>>
>>         self.setGeometry(300, 300, 300, 160)
>>         self.setWindowTitle('Cambio valor de etiqueta')
>>         self.show()
>>
>>     def saludar(self):
>>         print('Si entre')
>>         self.initGui.lBD.setText('Hola')
>>
>> def main():
>>     app = QtGui.QApplication(sys.argv)
>>     ex = init()
>>     sys.exit(app.exec_())
>>
>> if __name__ == '__main__':
>>     main()
>>
>>
>> Espero alguien me pueda orientar con esto, desde ya muchas gracias.
>>
>> hiram
>>
>>
>> _______________________________________________
>> Python-mx mailing list
>> Python-mx at python.org
>> https://mail.python.org/mailman/listinfo/python-mx
>>
>>
>
>
> --
> ---
> Noe Nieto
> NNieto Consulting Services
> M: nnieto at noenieto.com
> W: http://noenieto.com
> T:  @tzicatl <https://twitter.com/#%21/tzicatl>
> Li: Perfil en LinkedIn <http://www.linkedin.com/profile/view?id=84300665>
> _______________________________________________
> Python-mx mailing list
> Python-mx at python.org
> https://mail.python.org/mailman/listinfo/python-mx
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-mx/attachments/20160313/d09401cf/attachment-0001.html>


More information about the Python-mx mailing list