<DIV> </DIV>
<DIV>
<DIV><A href="http://www.pythonfan.org/forum.php?mod=viewthread&tid=10378#lastpost">http://www.pythonfan.org/forum.php?mod=viewthread&tid=10378#lastpost</A><BR></DIV>
<DIV><BR></DIV>
<DIV style="PADDING-BOTTOM: 2px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; FONT-FAMILY: Arial Narrow; FONT-SIZE: 12px; PADDING-TOP: 2px">------------------ Original ------------------</DIV>
<DIV style="PADDING-BOTTOM: 8px; PADDING-LEFT: 8px; PADDING-RIGHT: 8px; BACKGROUND: #efefef; FONT-SIZE: 12px; PADDING-TOP: 8px">
<DIV><B>From: </B> "pyqt-request"<pyqt-request@riverbankcomputing.com>;</DIV>
<DIV><B>Date: </B> Wed, Jul 31, 2013 07:00 PM</DIV>
<DIV><B>To: </B> "pyqt"<pyqt@riverbankcomputing.com>; <WBR></DIV>
<DIV></DIV>
<DIV><B>Subject: </B> PyQt Digest, Vol 108, Issue 34</DIV></DIV>
<DIV><BR></DIV>Send PyQt mailing list submissions to<BR>pyqt@riverbankcomputing.com<BR><BR>To subscribe or unsubscribe via the World Wide Web, visit<BR>http://www.riverbankcomputing.com/mailman/listinfo/pyqt<BR>or, via email, send a message with subject or body 'help' to<BR>pyqt-request@riverbankcomputing.com<BR><BR>You can reach the person managing the list at<BR>pyqt-owner@riverbankcomputing.com<BR><BR>When replying, please edit your Subject line so it is more specific<BR>than "Re: Contents of PyQt digest..."<BR><BR><BR>Today's Topics:<BR><BR> 1. how to use the button to control the program (??)<BR><BR><BR>----------------------------------------------------------------------<BR><BR>Message: 1<BR>Date: Wed, 31 Jul 2013 00:27:05 +0100<BR>From: ?? <jiwen0304@gmail.com><BR>To: "pyqt@riverbankcomputing.com" <pyqt@riverbankcomputing.com><BR>Subject: [PyQt] how to use the button to control the program<BR>Message-ID:<BR><CAPnMyV74ztvVF=MJ1n5sASBES9Lbz+vTYPnUy-PmKCeTxT6+dQ@mail.gmail.com><BR>Content-Type: text/plain; charset="iso-8859-1"<BR><BR>Hi,all, I want to use a button to control when the program start in pyqt4,<BR>in other words, when I press the start button, the program will work. I<BR>wrote some code, but it doesn't work. please help me to correct it. Thanks<BR>in advance.<BR><BR>Best regards<BR>Harry<BR><BR>import sys<BR>from PyQt4 import QtGui<BR>from PyQt4 import QtCore<BR>import time<BR><BR>class Example(QtGui.QWidget):<BR> def __init__(self):<BR> super(Example, self).__init__()<BR> self.initUI()<BR><BR> def initUI(self):<BR><BR> nowtime = '0000-00-00 00:00:00'<BR> timeEdit = QtGui.QLabel(str(nowtime),self)<BR> timeEdit.resize(timeEdit.sizeHint())<BR> timeEdit.move(110,30)<BR><BR> QtCore.QTimer.singleShot(1000,lambda:self.newtime(timeEdit))<BR><BR> startbtn = QtGui.QPushButton('Start', self)<BR> startbtn.setToolTip('Click it to <b>start</b> the program')<BR> startbtn.clicked.connect(self.newtime(timeEdit))<BR> startbtn.resize(startbtn.sizeHint())<BR> startbtn.move(200, 340)<BR><BR> qbtn = QtGui.QPushButton('Quit', self)<BR> qbtn.setToolTip('Click it and <b>quit</b> the program')<BR> qbtn.clicked.connect(QtCore.QCoreApplication.instance().quit)<BR> qbtn.resize(qbtn.sizeHint())<BR> qbtn.move(400, 340)<BR><BR> self.setGeometry(300, 200, 600, 400)<BR> self.setWindowTitle('Battery status')<BR> self.show()<BR><BR> def newtime(self,timeEdit):<BR> nowtime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())<BR> timeEdit.setText(str(nowtime))<BR> QtCore.QTimer.singleShot(1000,lambda:self.newtime(timeEdit))<BR><BR>def main():<BR><BR> app = QtGui.QApplication(sys.argv)<BR> ex = Example()<BR> sys.exit(app.exec_())<BR><BR>if __name__ == '__main__':<BR> main()<BR><BR>*when executing the program, there is something wrong:*<BR>**<BR>*Traceback (most recent call last):<BR> File "C:\Python\calendar.py", line 62, in <module><BR> main()<BR> File "C:\Python\calendar.py", line 57, in main<BR> ex = Example()<BR> File "C:\Python\calendar.py", line 15, in __init__<BR> self.initUI()<BR> File "C:\Python\calendar.py", line 32, in initUI<BR> startbtn.clicked.connect(self.newtime(timeEdit))<BR>TypeError: connect() slot argument should be a callable or a signal, not<BR>'NoneType'*<BR>-------------- next part --------------<BR>An HTML attachment was scrubbed...<BR>URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20130731/d5ff8914/attachment-0001.html><BR><BR>------------------------------<BR><BR>_______________________________________________<BR>PyQt mailing list<BR>PyQt@riverbankcomputing.com<BR>http://www.riverbankcomputing.com/mailman/listinfo/pyqt<BR><BR>End of PyQt Digest, Vol 108, Issue 34<BR>*************************************<BR>.<BR>
<DIV></DIV></DIV>