[PyQt] How to change the value which is shown on GUI

吉文 jiwen0304 at gmail.com
Fri Jul 26 17:44:56 BST 2013


Hello list, I want to design a battery monitoring system via raspberrypi.
The voltage of battery is real changing data, I try to write some code, but
the voltage can not change when I change the value of voltage.

here is part of my code:

import sys
from PyQt4 import QtGui,QtCore
import time

class Example(QtGui.QWidget):

        def __init__(self):
              super(Example,self).__init__()

              self.initUI()

         def initUI(self):
               voltage=12 #e.g. I get the value of voltage is 12v

               voltageEdit=QtGui.QLabel(str(voltage),self)
               voltageEdit.resize(voltageEdit.sizeHint())
               voltageEdit.move(160,100)

               time.sleep(5) # I want the GUI shows another value of
voltage 5 seconds later

               voltage=22
               voltageEdit=QtGui.QLabel(str(voltage),self)
               voltageEdit.resize(voltageEdit.sizeHint())
               voltageEdit.move(160,100)

               grid=QtGui.QGridLayout()
               self.setLayout(grid)

               self.setGeometry(300,200,600,400)
               self.setWindowTitle("battery status")
               self.show()

def main():

         app=QtGui.QApplication(sys.argv)
         ex=Example()
         sys.exit(app.exec())

if __name__='__main__':
         main()


When I executed this code, GUI shows the voltage is 12, and it will not
change, please tell me how to fix it.

thanks in advance,

Harry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20130726/f8694add/attachment.html>


More information about the PyQt mailing list