Click here to Skip to main content
15,886,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have problems with runing following program. I want that when i press push button it start function. but function start before i press the button. here is my code


gui.py


from PySide.QtCore import *
from PySide.QtGui import *
import sys
import showGui
import time


class Dialog(QDialog, showGui.Ui_Dialog):

def __init__(self, parent=None):
super(Dialog, self).__init__(parent)
self.setupUi(self)

self.connect(self.showButton, SIGNAL( 'clicked()' ), self.processData())


# def ShowMessageBox(self):
# QMessageBox.information(self,'Hello','Hello there' + self.nameEdit.text())

def processData(self):
time.sleep(6)
QMessageBox.information(self, 'Done!', 'Done')

app = QApplication(sys.argv)
form = Dialog()
form.show()
app.exec_()






showGui.py


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

# Form implementation generated from reading ui file 'show.ui'
#
# Created: Tue Apr 08 14:02:39 2014
# by: PyQt4 UI code generator 4.10.4
#
# WARNING! All changes made in this file will be lost!

from PySide import QtCore, QtGui

try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s

try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)

class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName(_fromUtf8("Dialog"))
Dialog.resize(379, 156)
self.nameEdit = QtGui.QLineEdit(Dialog)
self.nameEdit.setGeometry(QtCore.QRect(30, 40, 131, 31))
self.nameEdit.setText(_fromUtf8(""))
self.nameEdit.setObjectName(_fromUtf8("nameEdit"))
self.showButton = QtGui.QPushButton(Dialog)
self.showButton.setGeometry(QtCore.QRect(200, 40, 121, 31))
self.showButton.setObjectName(_fromUtf8("showButton"))

self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
Dialog.setTabOrder(self.showButton, self.nameEdit)

def retranslateUi(self, Dialog):
Dialog.setWindowTitle(_translate("Dialog", "Dialog", None))
self.nameEdit.setPlaceholderText(_translate("Dialog", "What is your name?", None))
self.showButton.setText(_tr
Posted
Updated 8-Apr-14 23:23pm
v4
Comments
[no name] 13-Jun-14 1:07am    
Always, try to format your code to increase readability.

1 solution

I suppose, It is no longer actual for the author, but for next generations:

Your function starts before you press the button because you call it explicitly:
Python
self.connect(self.showButton, SIGNAL( 'clicked()' ), self.processData())


Probably, you wanted to write:

Python
self.connect(self.showButton, SIGNAL( 'clicked()' ), self.processData)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900