hello,

Using Python 2.7, PyQt4, Qt Designer, and used pyuic4... I think thats it... windows 7?

I have a GUI i created in Qt Designer. It has one button and one LCD number. I was trying to get the button to start and reset a timer, and have the elapsed time displayed as value on the LCD number in hh:mm:ss format.

I have done numberous searches online, and found examples in other languages except for python? I have found examples that print time, but nothing in python which links to the LCD number from Qt Designer? Maybe it cant be done? Ive seen sliders and combo boxes linked to LCD number... but no buttons?

oh i almsot forgot, im also hoping that a window can "pop-up" after 40 minutes and say "Great Job, Nothing can slow you down!"

Here is my code... (I think im looking for the rest of "def doStartReset(self):" function/method)...

I hope i've posted everything you need...

thanks in advance guys! and gals!!! :)

#!/usr/bin/python2.7
import sys
from PyQt4 import QtGui,QtCore
from timer_ui import *

class MyForm(QtGui.QMainWindow):
        def __init__(self, parent=None):
                #build parent user interface
                QtGui.QWidget.__init__(self, parent)
                self.ui = Ui_MainWindow()
                self.ui.setupUi(self)

                QtCore.QObject.connect(self.ui.btnStartReset, QtCore.SIGNAL('clicked()'), self.doStartReset)

        def doStartReset(self):



if __name__ == "__main__":
        #This function means this was run directly, not called from another python file.
        app = QtGui.QApplication(sys.argv)
        myapp = MyForm()
        myapp.show()
        sys.exit(app.exec_())

here is the gui in ui.py form if you need to peek at it!

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'timer.ui'

from PyQt4 import QtCore, QtGui

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    _fromUtf8 = lambda s: s

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName(_fromUtf8("MainWindow"))
        MainWindow.resize(340, 205)
        self.centralwidget = QtGui.QWidget(MainWindow)
        self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
        self.widget = QtGui.QWidget(self.centralwidget)
        self.widget.setGeometry(QtCore.QRect(40, 50, 261, 81))
        self.widget.setObjectName(_fromUtf8("widget"))
        self.gridLayout = QtGui.QGridLayout(self.widget)
        self.gridLayout.setMargin(0)
        self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
        self.btnStartReset = QtGui.QPushButton(self.widget)
        self.btnStartReset.setObjectName(_fromUtf8("btnStartReset"))
        self.gridLayout.addWidget(self.btnStartReset, 0, 0, 1, 1)
        self.lcd40MinTimer = QtGui.QLCDNumber(self.widget)
        self.lcd40MinTimer.setObjectName(_fromUtf8("lcd40MinTimer"))
        self.gridLayout.addWidget(self.lcd40MinTimer, 0, 1, 1, 1)
        MainWindow.setCentralWidget(self.centralwidget)

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

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8))
        self.btnStartReset.setText(QtGui.QApplication.translate("MainWindow", "Start / Reset", None, QtGui.QApplication.UnicodeUTF8))

Hello guys, just an update... ive been working on this off and on for the past few days still.... not much progress, but some.. maybe someone finds this thread and it is helpful to them... ill continue working on it and post solution as soon as i get it! I adapted it from a slider and lcd number script... so im still going to change the lcd format to hh:mm:ss, change the button function to include start, stop and reset all in one button... and trigger event at 40 minutes... getting closer! :) Cheers...

#!/usr/bin/python
# -*- coding: utf-8 -*-

"""
this website has great tutorials: ZetCode PyQt4 tutorial

I took most of this script from there, so will leave the acknowledgements!

website: zetcode.com

 
"""

import sys
from PyQt4 import QtGui, QtCore

class Example(QtGui.QWidget):

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

        self.initUI()

    def initUI(self):

        self.lcd = QtGui.QLCDNumber(self)
        self.lcd.setGeometry(30, 40, 200, 25)

        self.btn = QtGui.QPushButton('Start', self)
        self.btn.move(40, 80)
        self.btn.clicked.connect(self.doAction)

        self.timer = QtCore.QBasicTimer()
        self.step = 0

        self.setGeometry(300, 300, 280, 170)
        self.setWindowTitle('QtGui.QLCDNumber')
        self.show()

    def timerEvent(self, e):

        if self.step >= 100:
            self.timer.stop()
            self.btn.setText('Finished')
            return

        self.step = self.step + 1
        self.lcd.display(self.step)

    def doAction(self):

        if self.timer.isActive():
            self.timer.stop()
            self.btn.setText('Start')
        else:
            self.timer.start(100, self)
            self.btn.setText('Stop')

def main():

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


if __name__ == '__main__':
    main()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.