http://www.pythonfan.org/forum.php?mod=viewthread&tid=10378#lastpost

 

 ------------------ Original ------------------
  From:  "pyqt-request"<pyqt-requ...@riverbankcomputing.com>;
 Date:  Wed, Jul 31, 2013 07:00 PM
 To:  "pyqt"<pyqt@riverbankcomputing.com>; 
 
 Subject:  PyQt Digest, Vol 108, Issue 34

 

Send PyQt mailing list submissions to
pyqt@riverbankcomputing.com

To subscribe or unsubscribe via the World Wide Web, visit
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
or, via email, send a message with subject or body 'help' to
pyqt-requ...@riverbankcomputing.com

You can reach the person managing the list at
pyqt-ow...@riverbankcomputing.com

When replying, please edit your Subject line so it is more specific
than "Re: Contents of PyQt digest..."


Today's Topics:

   1. how to use the button to control the program (??)


----------------------------------------------------------------------

Message: 1
Date: Wed, 31 Jul 2013 00:27:05 +0100
From: ?? <jiwen0...@gmail.com>
To: "pyqt@riverbankcomputing.com" <pyqt@riverbankcomputing.com>
Subject: [PyQt] how to use the button to control the program
Message-ID:
<CAPnMyV74ztvVF=mj1n5sasbes9lbz+vtypnuy-pmkcetxt6...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Hi,all, I want to use a button to control when the program start in pyqt4,
in other words, when I press the start button, the program will work. I
wrote some code, but it doesn't work. please help me to correct it. Thanks
in advance.

Best regards
Harry

import sys
from PyQt4 import QtGui
from PyQt4 import QtCore
import time

class Example(QtGui.QWidget):
    def __init__(self):
        super(Example, self).__init__()
        self.initUI()

    def initUI(self):

        nowtime = '0000-00-00 00:00:00'
        timeEdit = QtGui.QLabel(str(nowtime),self)
        timeEdit.resize(timeEdit.sizeHint())
        timeEdit.move(110,30)

        QtCore.QTimer.singleShot(1000,lambda:self.newtime(timeEdit))

        startbtn = QtGui.QPushButton('Start', self)
        startbtn.setToolTip('Click it to <b>start</b> the program')
        startbtn.clicked.connect(self.newtime(timeEdit))
        startbtn.resize(startbtn.sizeHint())
        startbtn.move(200, 340)

        qbtn = QtGui.QPushButton('Quit', self)
        qbtn.setToolTip('Click it and <b>quit</b> the program')
        qbtn.clicked.connect(QtCore.QCoreApplication.instance().quit)
        qbtn.resize(qbtn.sizeHint())
        qbtn.move(400, 340)

        self.setGeometry(300, 200, 600, 400)
        self.setWindowTitle('Battery status')
        self.show()

    def newtime(self,timeEdit):
        nowtime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
        timeEdit.setText(str(nowtime))
        QtCore.QTimer.singleShot(1000,lambda:self.newtime(timeEdit))

def main():

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

if __name__ == '__main__':
    main()

*when executing the program, there is something wrong:*
**
*Traceback (most recent call last):
  File "C:\Python\calendar.py", line 62, in <module>
    main()
  File "C:\Python\calendar.py", line 57, in main
    ex = Example()
  File "C:\Python\calendar.py", line 15, in __init__
    self.initUI()
  File "C:\Python\calendar.py", line 32, in initUI
    startbtn.clicked.connect(self.newtime(timeEdit))
TypeError: connect() slot argument should be a callable or a signal, not
'NoneType'*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20130731/d5ff8914/attachment-0001.html>

------------------------------

_______________________________________________
PyQt mailing list
PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

End of PyQt Digest, Vol 108, Issue 34
*************************************
.
_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to