I'm new to pyQt4 and i need to create GUI using pyQt4 and python 3.5.
I have long process which does not have exact time duration to be executed. time duration is varying according to the inputs that I use in the process at each time. There are examples about adding progress bars by using timers.but in my case i don't know the exact time duration.
I need to complete a progress bar according to the time taken by the process.as in the my code this process is methodtobeexecute(). could someone help me out to resolve this problem with a code example with a explanation. Thanks in advance....
this is my code and so far it completes the progress bar using QTimer.but what i want is complete the progress bar meanwhile the methodtobeexecute() method finishes its tasks.(QTimer has used only for check the progrss bar here)
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'pro2.ui'
#
# Created by: PyQt4 UI code generator 4.11.4
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
import sys
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_Form(QtGui.QWidget):
def __init__(self):
QtGui.QWidget.__init__(self)
self.setupUi(self)
def setupUi(self, Form):
Form.setObjectName(_fromUtf8("Form"))
Form.resize(400, 300)
self.progressBar = QtGui.QProgressBar(Form)
self.progressBar.setGeometry(QtCore.QRect(160, 60, 118, 23))
self.progressBar.setProperty("value", 24)
self.progressBar.setObjectName(_fromUtf8("progressBar"))
self.pushButton = QtGui.QPushButton(Form)
self.pushButton.setGeometry(QtCore.QRect(170, 140, 75, 23))
self.pushButton.setObjectName(_fromUtf8("pushButton"))
# # restarts the 'QProgressBar'
self.progressBar.reset()
# creates a 'QTimer'
self.qtimer = QtCore.QTimer()
# connects the 'QTimer.timeout()' signal with the 'qtimer_timeout()' slot
self.qtimer.timeout.connect(self.qtimer_timeout)
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
Form.setWindowTitle(_translate("Form", "Form", None))
self.pushButton.setText(_translate("Form", "start", None))
self.pushButton.clicked.connect(self.qpushbutton_clicked)
def qpushbutton_clicked(self):
self.progressBar.reset()
#this is the method that needs the time to complete the progress bar
self.methodtobeexecute()
self.qtimer.start(40)
def qprogressbar_value_changed(self, value):
if value == self.progressBar.maximum():
# stops the 'QTimer'
self.qtimer.stop()
def qtimer_timeout(self):
# gets the current value of the 'QProgressBar'
value = self.progressBar.value()
# adds 1 to the current value of the 'QProgressBar'
self.progressBar.setValue(value + 1)
def methodtobeexecute(self):
for i in 400:
print(i)
def main():
app = QtGui.QApplication(sys.argv)
mw = Ui_Form()
mw.show()
sys.exit(app.exec_())
if __name__ == "__main__":
main()
Related
I have this simple window (design.py) derived from Qt designer, which consists of three radio buttons:
# -*- coding: utf-8 -*-
from PyQt4 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_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.setEnabled(True)
MainWindow.resize(158, 110)
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.myradioButton1 = QtGui.QRadioButton(self.centralwidget)
self.myradioButton1.setGeometry(QtCore.QRect(20, 10, 102, 22))
self.myradioButton1.setObjectName(_fromUtf8("myradioButton1"))
self.myradioButton2 = QtGui.QRadioButton(self.centralwidget)
self.myradioButton2.setGeometry(QtCore.QRect(20, 40, 102, 22))
self.myradioButton2.setObjectName(_fromUtf8("myradioButton2"))
self.myradioButton3 = QtGui.QRadioButton(self.centralwidget)
self.myradioButton3.setGeometry(QtCore.QRect(20, 70, 102, 22))
self.myradioButton3.setObjectName(_fromUtf8("myradioButton3"))
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtGui.QStatusBar(MainWindow)
self.statusbar.setObjectName(_fromUtf8("statusbar"))
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow", None))
self.myradioButton1.setText(_translate("MainWindow", "RadioButton1", None))
self.myradioButton2.setText(_translate("MainWindow", "RadioButton2", None))
self.myradioButton3.setText(_translate("MainWindow", "RadioButton3", None))
and I have added this code, in order to monitor which radio button is checked.
# -*- coding: utf-8 -*-
from PyQt4 import QtGui, QtCore
import sys
import design
class ExampleApp(QtGui.QMainWindow, design.Ui_MainWindow):
def __init__(self, parent=None):
super(ExampleApp, self).__init__(parent)
self.setupUi(self)
self.myradioButton1.toggled.connect(self.myradioButton1_function)
self.myradioButton2.toggled.connect(self.myradioButton1_function)
self.myradioButton3.toggled.connect(self.myradioButton1_function)
def myradioButton1_function(self):
if self.myradioButton1.isChecked():
print 'myradioButton1 is Checked'
if self.myradioButton2.isChecked():
print 'myradioButton2 is Checked'
if self.myradioButton3.isChecked():
print 'myradioButton3 is Checked'
def main():
app = QtGui.QApplication(sys.argv)
form = ExampleApp()
form.show()
app.exec_()
if __name__ == '__main__':
main()
I noticed that if radioButton1 is checked, it seems to work fine, but if radiobutton2 or radiobutton3 are checked, the check message is printed twice.
On the other hand, if I connect every signal to a different function, like this:
class ExampleApp(QtGui.QMainWindow, design.Ui_MainWindow):
def __init__(self, parent=None):
super(ExampleApp, self).__init__(parent)
self.setupUi(self)
self.myradioButton1.toggled.connect(self.myradioButton1_function)
self.myradioButton2.toggled.connect(self.myradioButton2_function)
self.myradioButton3.toggled.connect(self.myradioButton3_function)
def myradioButton1_function(self):
if self.myradioButton1.isChecked():
print 'myradioButton1 is Checked'
def myradioButton2_function(self):
if self.myradioButton2.isChecked():
print 'myradioButton2 is Checked'
def myradioButton3_function(self):
if self.myradioButton3.isChecked():
print 'myradioButton3 is Checked'
then it works as expected.
So, I guess that the trouble occurs when I want to connect many signal to one function. Could someone explain this behavior?
Any thoughts would be appreciated.
The toggle() signal is emitted every time any radio button's state changes. As a result, the toggle() signal is emitted when you click on a radio button and that radio button's state changes from unchecked to checked, and if clicking on the radio button automatically unchecks another radio button, then the toggle() signal is emitted again because the other radio button's state changes from checked to unchecked.
You can see that in action by adding the following line to the end of your slot:
print self.sender().text() + ' was toggled'
Use the clicked() signal instead--a radio button whose state was automatically changed from checked to unchecked was never clicked.
I'm using pyqt4 and python 2.7.11. I have a problem with the file/directory dialogs: I don't know what to use as the parent parameter.
If I use "self" or "None", PyCharm tells me that it's expecting "QFileDialog", and it got "AppTest" and "None" instead, respectively.
If I use "parent=self" or "parent=None", PyCharm tells me that the "self" parameter is unfilled.
Please see the example code below; I'm using Qt Designer to create the ui, let me know if you need that code as well.
import sys
from PyQt4 import QtGui
import ui_test as main_frame
class AppTest(QtGui.QMainWindow, main_frame.Ui_MainAppWindow):
def __init__(self, parent=None):
super(AppTest, self).__init__(parent)
self.setupUi(self)
self.pushButton1.clicked.connect(self.dialog1)
self.show()
def dialog1(self):
file1 = str(QtGui.QFileDialog.getOpenFileName(
parent=self,
caption="Locate file 1",
directory="",
filter="Graphics files (*.jpg *.jpeg)"))
print file1
def main():
app = QtGui.QApplication(sys.argv)
gui = AppTest()
sys.exit(app.exec_())
if __name__ == "__main__":
main()
EDIT: Here's the code for the ui:
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'test_ui.ui'
#
# Created by: PyQt4 UI code generator 4.11.4
#
# WARNING! All changes made in this file will be lost!
from PyQt4 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_MainAppWindow(object):
def setupUi(self, MainAppWindow):
MainAppWindow.setObjectName(_fromUtf8("MainAppWindow"))
MainAppWindow.resize(269, 195)
self.centralwidget = QtGui.QWidget(MainAppWindow)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.verticalLayout = QtGui.QVBoxLayout(self.centralwidget)
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
self.pushButton1 = QtGui.QPushButton(self.centralwidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton1.sizePolicy().hasHeightForWidth())
self.pushButton1.setSizePolicy(sizePolicy)
self.pushButton1.setObjectName(_fromUtf8("pushButton1"))
self.verticalLayout.addWidget(self.pushButton1)
self.pushButton2 = QtGui.QPushButton(self.centralwidget)
self.pushButton2.setObjectName(_fromUtf8("pushButton2"))
self.verticalLayout.addWidget(self.pushButton2)
MainAppWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainAppWindow)
QtCore.QMetaObject.connectSlotsByName(MainAppWindow)
def retranslateUi(self, MainAppWindow):
MainAppWindow.setWindowTitle(_translate("MainAppWindow", "MainWindow", None))
self.pushButton1.setText(_translate("MainAppWindow", "PushButton1", None))
self.pushButton2.setText(_translate("MainAppWindow", "PushButton2", None))
this is my fill
this code is generated by pyuic
im using pyqt4
and python 2.7
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'editgui.ui'
#
# Created: Mon Nov 24 17:33:07 2014
# by: PyQt4 UI code generator 4.11.3
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
import PyQt4
import sys
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_Form(object):
def setupUi(self, Form):
Form.setObjectName(_fromUtf8("Form"))
Form.setEnabled(True)
Form.resize(1032, 779)
Form.setMinimumSize(QtCore.QSize(1032, 779))
Form.setMaximumSize(QtCore.QSize(1032, 779))
self.textEdit = QtGui.QTextEdit(Form)
self.textEdit.setGeometry(QtCore.QRect(90, 110, 361, 221))
self.textEdit.setObjectName(_fromUtf8("textEdit"))
self.textEdit_2 = QtGui.QTextEdit(Form)
self.textEdit_2.setGeometry(QtCore.QRect(90, 430, 361, 261))
self.textEdit_2.setObjectName(_fromUtf8("textEdit_2"))
self.lineEdit = QtGui.QLineEdit(Form)
self.lineEdit.setGeometry(QtCore.QRect(90, 380, 361, 20))
...
self.label_6.setGeometry(QtCore.QRect(510, 90, 46, 13))
self.label_6.setObjectName(_fromUtf8("label_6"))
self.retranslateUi(Form)
QtCore.QObject.connect(self.lineEdit_2, QtCore.SIGNAL(_fromUtf8("textChanged(QString)")), self.pushButton.show)
QtCore.QObject.connect(self.textEdit, QtCore.SIGNAL(_fromUtf8("textChanged()")), self.pushButton.show)
QtCore.QObject.connect(self.lineEdit, QtCore.SIGNAL(_fromUtf8("textChanged(QString)")), self.pushButton.show)
QtCore.QObject.connect(self.textEdit_2, QtCore.SIGNAL(_fromUtf8("textChanged()")), self.pushButton.show)
QtCore.QObject.connect(self.lineEdit_3, QtCore.SIGNAL(_fromUtf8("textChanged(QString)")), self.pushButton.show)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
Form.setWindowTitle(_translate("Form", "Form", None))
self.label.setText(_translate("Form", "titel", None))
self.label_2.setText(_translate("Form", "beschrijving", None))
self.label_3.setText(_translate("Form", "frans", None))
self.label_4.setText(_translate("Form", "titel", None))
self.label_5.setText(_translate("Form", "beschrijving", None))
self.pushButton.setText(_translate("Form", "save", None))
self.pushButton_2.setText(_translate("Form", "run", None))
self.label_6.setText(_translate("Form", "website", None))
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
ex = Ui_Form()
ex.show
sys.exit(app.exec_())
end this is the error i get
Traceback (most recent call last):
File "C:\Users\IT4PROGRESS\Desktop\2dehands gui\output.py", line 99, in <module>
ex.show
AttributeError: 'Ui_Form' object has no attribute 'show'
i use python 2.7
Firstly, don't edit file generated by pyuic. Make another .py file and import it. That way, instead of trying to show() the generated UI file directly, you can make a QMainWindow based class that you can run show() on and it will build the generated ui file for you. Like this:
import sys
from PyQt4 import QtCore, QtGui
from Ui_Form import Ui_Form
class Main(QtGui.QMainWindow):
def __init__(self):
super(Main, self).__init__()
# build ui
self.ui = Ui_Form()
self.ui.setupUi(self)
# connect signals
self.ui.some_button.connect(self.on_button)
def on_button(self):
print 'Button clicked!'
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
main = Main()
main.show()
sys.exit(app.exec_())
I wish to change the image of a pixmap being displayed in a window automatically using a while loop that has a defined delay and uses locations of images stored in a string list.
All possibilities I tried led to the first image being displayed but not changing at runtime.
Any changes gets reflected only after the program has completed all kinds of execution.
from PyQt4 import QtCore, QtGui
import time
import sys
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_Form(QtGui.QWidget):
def __init__(self):
QtGui.QWidget.__init__(self)
self.setupUi(self)
def setupUi(self, Form):
Form.setObjectName(_fromUtf8("Form"))
Form.resize(598, 555)
self.horizontalLayout = QtGui.QHBoxLayout(Form)
self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
self.start_pulse = QtGui.QPushButton(Form)
self.start_pulse.setObjectName(_fromUtf8("start_pulse"))
self.horizontalLayout.addWidget(self.start_pulse)
self.label = QtGui.QLabel(Form)
self.label.setAutoFillBackground(True)
self.label.setText(_fromUtf8(""))
self.label.setPixmap(QtGui.QPixmap(_fromUtf8("GUI.png")))
self.label.setScaledContents(True)
self.label.setObjectName(_fromUtf8("label"))
self.horizontalLayout.addWidget(self.label)
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
Form.setWindowTitle(_translate("Form", "Form", None))
self.start_pulse.setText(_translate("Form", "start", None))
self.start_pulse.clicked.connect(self.soumyajit)
def soumyajit(self):
j=0
while(1):
print("change")
if j==0:
self.label.setPixmap(QtGui.QPixmap(_fromUtf8("GUI2.png")))
if j==1:
self.label.setPixmap(QtGui.QPixmap(_fromUtf8("GUI.png")))
if j==2:
self.label.setPixmap(QtGui.QPixmap(_fromUtf8("GUI2.png")))
if j==3:
self.label.setPixmap(QtGui.QPixmap(_fromUtf8("GUI.png")))
j=j+1
#delay
time.sleep(.5)
if __name__=='__main__':
app=QtGui.QApplication(sys.argv)
ex = Ui_Form()
ex.show()
sys.exit(app.exec_())
Following code what I modified from your code, it works well:
Original Code from Changing Pixmap image automatically at runtime in PyQt
Modified for solving problem by WonJong Kim (wjkim#etri.re.kr)
import sys
import time
import numpy
from PyQt4 import QtCore, QtGui
import PyQt4.Qwt5 as Qwt
numPoints=1000
xs=numpy.arange(numPoints)
ys=numpy.sin(3.14159*xs*10/numPoints) #this is our data
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_Form(QtGui.QWidget):
def __init__(self):
QtGui.QWidget.__init__(self)
self.setupUi(self)
self.index = 0
def setupUi(self, Form):
Form.setObjectName(_fromUtf8("Form"))
Form.resize(500, 300)
self.horizontalLayout = QtGui.QHBoxLayout(Form)
self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
self.start_pulse = QtGui.QPushButton(Form)
self.start_pulse.setObjectName(_fromUtf8("start_pulse"))
self.stop_pulse = QtGui.QPushButton(Form)
self.stop_pulse.setObjectName(_fromUtf8("stop_pulse"))
self.horizontalLayout.addWidget(self.start_pulse)
self.horizontalLayout.addWidget(self.stop_pulse)
self.label = QtGui.QLabel(Form)
self.label.setAutoFillBackground(True)
self.label.setText(_fromUtf8(""))
self.label.setPixmap(QtGui.QPixmap(_fromUtf8("GUI.png")))
self.label.setScaledContents(True)
self.label.setObjectName(_fromUtf8("label"))
self.horizontalLayout.addWidget(self.label)
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def refreshUi(self):
if self.index%10==0:
self.label.setPixmap(QtGui.QPixmap(_fromUtf8("Images/10.jpg")))
if self.index%10==1:
self.label.setPixmap(QtGui.QPixmap(_fromUtf8("Images/1.jpg")))
if self.index%10==2:
self.label.setPixmap(QtGui.QPixmap(_fromUtf8("Images/2.jpg")))
if self.index%10==3:
self.label.setPixmap(QtGui.QPixmap(_fromUtf8("Images/3.jpg")))
if self.index%10==4:
self.label.setPixmap(QtGui.QPixmap(_fromUtf8("Images/4.jpg")))
if self.index%10==5:
self.label.setPixmap(QtGui.QPixmap(_fromUtf8("Images/5.jpg")))
if self.index%10==6:
self.label.setPixmap(QtGui.QPixmap(_fromUtf8("Images/6.jpg")))
if self.index%10==7:
self.label.setPixmap(QtGui.QPixmap(_fromUtf8("Images/7.jpg")))
if self.index%10==8:
self.label.setPixmap(QtGui.QPixmap(_fromUtf8("Images/8.jpg")))
if self.index%10==9:
self.label.setPixmap(QtGui.QPixmap(_fromUtf8("Images/9.jpg")))
def retranslateUi(self, Form):
Form.setWindowTitle(_translate("Form", "Form", None))
self.start_pulse.setText(_translate("Form", "start", None))
self.start_pulse.clicked.connect(self.start)
self.stop_pulse.setText(_translate("Form", "stop", None))
self.stop_pulse.clicked.connect(self.stop)
def start(self):
self.timer1.start(500.0) #set the interval (in ms)
def stop(self):
self.timer1.stop() #stop the timer
def change_index(self):
self.index += 1
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
win_plot = Ui_Form()
win_plot.index = 0
win_plot.timer = QtCore.QTimer() #start a timer (to call replot events)
win_plot.timer.start(100.0) #set the interval (in ms)
win_plot.connect(win_plot.timer, QtCore.SIGNAL('timeout()'), win_plot.refreshUi)
win_plot.timer1 = QtCore.QTimer() #start a timer (to call replot events)
win_plot.connect(win_plot.timer1, QtCore.SIGNAL('timeout()'),
win_plot.change_index)
# show the main window
win_plot.show()
sys.exit(app.exec_())
You run your loop in GUI thread so it's freezing your app. It is a bad approach. You should use QTimer instead. Use timeout() signal to do all your image changes inside special slot . QTimer is asynchronous so it will not freeze your app.
You can also call processEvents() inside loop but it is not good solution, timer is better than loop with sleep.
I am a python and qt-designer newbie user. I have made a simple python code for random generating numbers. Now what i want is when i click a button the output will be on GUI and not on terminal. So far i have managed to click a button and the output will be generated in terminal but that is not what i want.
So here is the qt GUI which i have made in QT-designer with no modification as to script. Thanks for any help!
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'qt_hello.ui'
#
# Created: Sat Jul 20 21:22:41 2013
# by: PyQt4 UI code generator 4.10.2
#
# WARNING! All changes made in this file will be lost!
from PyQt4 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_Form(object):
def setupUi(self, Form):
Form.setObjectName(_fromUtf8("Form"))
Form.resize(400, 300)
self.pushButton = QtGui.QPushButton(Form)
self.pushButton.setGeometry(QtCore.QRect(210, 230, 95, 23))
self.pushButton.setObjectName(_fromUtf8("pushButton"))
self.label = QtGui.QLabel(Form)
self.label.setGeometry(QtCore.QRect(80, 30, 121, 71))
self.label.setObjectName(_fromUtf8("label"))
self.retranslateUi(Form)
QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL(_fromUtf8("clicked()")), self.label.clear)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
Form.setWindowTitle(_translate("Form", "Form", None))
self.pushButton.setText(_translate("Form", "PushButton", None))
self.label.setText(_translate("Form", "TextLabel", None))
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
Form = QtGui.QWidget()
ui = Ui_Form()
ui.setupUi(Form)
Form.show()
sys.exit(app.exec_())
I think I understand your question, but I'm not entirely certain. Anyway, I think what you want to do is something like this. First, instead of clearing the label, replace it with something like:
QtCore.QObject.connect([...], self.button_clicked)
Now, you need to create that function in your class:
def button_clicked(self):
x = 100 # Generate your number here
self.label.setText("My number: {0}".format(x))