I made a GUI in Qt Designer and I have 144 check boxes. I want to connect all of them with a QPushButton to check and uncheck all of them.
How can I do that?
They are all inside of a QGridLayout.
They are named following a "trend", so I tried to write their names in a list and call each item of the list to check, but I did not manage.
This example is more or less like what I have
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'check.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_Form(object):
def setupUi(self, Form):
Form.setObjectName(_fromUtf8("Form"))
Form.resize(400, 300)
self.gridLayout = QtGui.QGridLayout(Form)
self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
self.checkBox_2 = QtGui.QCheckBox(Form)
self.checkBox_2.setObjectName(_fromUtf8("checkBox_2"))
self.gridLayout.addWidget(self.checkBox_2, 2, 0, 1, 2)
self.checkBox = QtGui.QCheckBox(Form)
self.checkBox.setObjectName(_fromUtf8("checkBox"))
self.gridLayout.addWidget(self.checkBox, 2, 2, 1, 1)
self.checkBox_3 = QtGui.QCheckBox(Form)
self.checkBox_3.setObjectName(_fromUtf8("checkBox_3"))
self.gridLayout.addWidget(self.checkBox_3, 3, 0, 1, 2)
self.checkBox_4 = QtGui.QCheckBox(Form)
self.checkBox_4.setObjectName(_fromUtf8("checkBox_4"))
self.gridLayout.addWidget(self.checkBox_4, 3, 2, 1, 1)
self.checkBox_5 = QtGui.QCheckBox(Form)
self.checkBox_5.setObjectName(_fromUtf8("checkBox_5"))
self.gridLayout.addWidget(self.checkBox_5, 1, 2, 1, 1)
self.checkBox_6 = QtGui.QCheckBox(Form)
self.checkBox_6.setObjectName(_fromUtf8("checkBox_6"))
self.gridLayout.addWidget(self.checkBox_6, 1, 0, 1, 1)
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
Form.setWindowTitle(_translate("Form", "Form", None))
self.checkBox_2.setText(_translate("Form", "CheckBox", None))
self.checkBox.setText(_translate("Form", "CheckBox", None))
self.checkBox_3.setText(_translate("Form", "CheckBox", None))
self.checkBox_4.setText(_translate("Form", "CheckBox", None))
self.checkBox_5.setText(_translate("Form", "CheckBox", None))
self.checkBox_6.setText(_translate("Form", "CheckBox", 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 want to make a button to check and uncheck all of them without having to type ao the connects
It is tedious to have to make many connections, but as you say you can create an object list with findChildren, but first add a button to the design.
class Ui_Form(object):
def setupUi(self, Form):
...
self.gridLayout.addWidget(self.checkBox_6, 1, 0, 1, 1)
self.btn = QtGui.QPushButton("Check", Form)
self.gridLayout.addWidget(self.btn, 4, 0, 1, 3)
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
...
Then we implement the logic in another class and we use findChildren to obtain the QCheckBox:
class Widget(QtGui.QWidget, Ui_Form):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.setupUi(self)
self.checkBoxList = self.findChildren(QtGui.QCheckBox)
self.btn.clicked.connect(self.onClicked)
def onClicked(self):
state = self.sender().text() == "Check"
for btn in self.checkBoxList:
btn.setChecked(state)
self.sender().setText("Uncheck" if state else "Check")
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
Form = Widget()
Form.show()
sys.exit(app.exec_())
Related
i have two windows,i want to hide it after three seconds by using Qt timer,but its overlapping...its probably occurs when window size sets to
"showMaximized"
from PyQt4 import QtCore, QtGui
from PyQt4 import QtGui
from PyQt4.QtCore import Qt, QPoint
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.showMaximized()
Form.setStyleSheet(_fromUtf8("background-color: rgb(0, 0, 0);"))
self.label = QtGui.QLabel(Form)
self.label.setGeometry(QtCore.QRect(450, 317, 300, 61))
self.label.setStyleSheet(_fromUtf8("font: 75 60pt \"Tlwg Mono\";color: rgb(255, 255, 255);"))
self.label.setObjectName(_fromUtf8("label"))
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
Form.setWindowTitle(_translate("Form", "Form", None))
self.label.setText(_translate("Form", "omniOS", None))
class Ui_Dialog1(object):
def setupUi(self, Dialog):
Dialog.setObjectName(_fromUtf8("Dialog"))
Dialog.showMaximized()
Dialog.setStyleSheet(_fromUtf8("background-color: rgb(0, 0, 0);"))
QtCore.QMetaObject.connectSlotsByName(Dialog)
self.centralwidget = QtGui.QWidget(Dialog)
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
Dialog.setWindowTitle(_translate("Dialog", "Dialog", None))
class Dialog(QtGui.QDialog, Ui_Form):
def __init__(self, parent=None):
super(Dialog, self).__init__(parent)
self.setupUi(self)
class Dialog1(QtGui.QDialog, Ui_Dialog1):
def __init__(self, parent=None):
super(Dialog1, self).__init__(parent)
self.setupUi(self)
def paintEvent(self, event):
painter = QtGui.QPainter(self)
painter.setPen(QtGui.QPen(QtCore.Qt.white))
painter.drawArc(QtCore.QRectF(640, 330, 35, 35), 0, 5750)
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
w1=Dialog()
w2=Dialog1()
def on_timeout():
w1.hide()
w2.show()
QtCore.QTimer.singleShot(3000, on_timeout)
sys.exit(app.exec_())
what I need to do is, I need to get
second window after three seconds when
size sets to maximized.
Form.showMaximized()
This change to (form.resize) its working what i expected.
Any help plz
You do not observe that w1 is closed because w2 is above w1, but if it is working, so you point out in the comments I understand that you want initially only visible w1 and after 3 seconds w2 is displayed and w1 is hidden, considering that the solution is the following:
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
w1=Dialog()
w2=Dialog1()
w2.hide()
QtCore.QTimer.singleShot(3000, w1.hide)
QtCore.QTimer.singleShot(3000, w2.showMaximized)
sys.exit(app.exec_())
I'm using pyqt4 with python 2.7 and I have a list view widget that I can't add items to it
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'add_category.ui'
#
# Created: Mon Mar 19 23:22:30 2018
# by: PyQt4 UI code generator 4.10
#
# 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_Dialog1(object):
def setupUi(self, Dialog):
Dialog.setObjectName(_fromUtf8("Dialog"))
Dialog.resize(608, 460)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(_fromUtf8(":/media/media/in.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
Dialog.setWindowIcon(icon)
self.gridLayout = QtGui.QGridLayout(Dialog)
self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
self.lineEdit = QtGui.QLineEdit(Dialog)
self.lineEdit.setObjectName(_fromUtf8("lineEdit"))
self.gridLayout.addWidget(self.lineEdit, 0, 1, 1, 1)
self.pushButton = QtGui.QPushButton(Dialog)
self.pushButton.setIcon(icon)
self.pushButton.setObjectName(_fromUtf8("pushButton"))
self.gridLayout.addWidget(self.pushButton, 0, 6, 1, 1)
self.label = QtGui.QLabel(Dialog)
font = QtGui.QFont()
font.setFamily(_fromUtf8("Adobe Arabic"))
font.setPointSize(24)
self.label.setFont(font)
self.label.setObjectName(_fromUtf8("label"))
self.gridLayout.addWidget(self.label, 0, 0, 1, 1)
self.listView = QtGui.QListView(Dialog)
self.listView.setObjectName(_fromUtf8("listView"))
entries = ['one','two', 'three']
for i in entries:
item = QtGui.QListView(i)
self.listView.addItem(item)
self.gridLayout.addWidget(self.listView, 1, 0, 1, 2)
self.pushButton_2 = QtGui.QPushButton(Dialog)
icon1 = QtGui.QIcon()
icon1.addPixmap(QtGui.QPixmap(_fromUtf8(":/media/media/ok.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.pushButton_2.setIcon(icon1)
self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
def go_back(self):
Dialog.hide()
self.pushButton_2.clicked.connect(go_back)
self.gridLayout.addWidget(self.pushButton_2, 2, 1, 1, 1)
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
Dialog.setWindowTitle(_translate("Dialog", "إضافة فئة", None))
self.lineEdit.setPlaceholderText(_translate("Dialog", "هنا يكتب الاسم الفئة الجديدة", None))
self.pushButton.setText(_translate("Dialog", "إضافة", None))
self.label.setText(_translate("Dialog", "إسـم الفئة الجديدة", None))
self.pushButton_2.setText(_translate("Dialog", "موافق", None))
import resrcs
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
Dialog = QtGui.QDialog()
ui = Ui_Dialog1()
ui.setupUi(Dialog)
Dialog.show()
sys.exit(app.exec_())
As you guys can see i used
entries = ['one','two', 'three']
for i in entries:
item = QtGui.QListView(i)
self.listView.addItem(item)
But it gave me an error that is talking about arguments and data types:
Traceback (most recent call last):
File "C:\python\townoftechwarehouse\add_category.py", line 84, in <module>
ui.setupUi(Dialog)
File "C:\python\townoftechwarehouse\add_category.py", line 54, in setupUi
item = QtGui.QListView(i)
TypeError: QListView(QWidget parent=None): argument 1 has unexpected type 'str'
[Finished in 1.7s]
Also, is it right to use ListView here or I should use listwidget?
In general, what is the difference between both !!
QListWidget is a class of higher level that makes the developer can handle it easily, for example QListWidget has a model of type QStantandardItemModel that can not be accessed, in addition to built the QListWidgetItem to handle the data, as you have seen is simple add data through functions like addItem() or addItems().
On the other hand QListView, from which QListWidget inherits, is of lower level, where you can customize many things, using custom models, etc.
You can use both:
QListView
self.listView = QtGui.QListView(Dialog)
self.listView.setObjectName(_fromUtf8("listView"))
entries = ['one', 'two', 'three']
model = QtGui.QStandardItemModel()
self.listView.setModel(model)
for i in entries:
item = QtGui.QStandardItem(i)
model.appendRow(item)
self.gridLayout.addWidget(self.listView, 1, 0, 1, 2)
QListWidget
self.listwidget = QtGui.QListWidget(Dialog)
entries = ['one', 'two', 'three']
self.listwidget.addItems(entries)
self.gridLayout.addWidget(self.listwidget, 1, 0, 1, 2)
I've created a MainWindow design called Ui_Dashboard within Qt Designer. I've also created a widget called "units_table", which I'd like to import and display within the Ui_Dashboard.
I've created a new class and inherited the Ui_Dashboard class, but for some reason cannot access the verticalLayout object. See code below:
dashboard.py
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'dashboard.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_Dashboard(object):
def setupUi(self, Dashboard):
Dashboard.setObjectName(_fromUtf8("Dashboard"))
Dashboard.resize(800, 600)
self.centralwidget = QtGui.QWidget(Dashboard)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.widget = QtGui.QWidget(self.centralwidget)
self.widget.setGeometry(QtCore.QRect(50, 21, 683, 360))
self.widget.setObjectName(_fromUtf8("widget"))
self.verticalLayout = QtGui.QVBoxLayout(self.widget)
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
self.horizontalLayout = QtGui.QHBoxLayout()
self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
self.units_button = QtGui.QPushButton(self.widget)
self.units_button.setCheckable(True)
self.units_button.setChecked(False)
self.units_button.setObjectName(_fromUtf8("units_button"))
self.horizontalLayout.addWidget(self.units_button)
self.calls_button = QtGui.QPushButton(self.widget)
self.calls_button.setCheckable(True)
self.calls_button.setObjectName(_fromUtf8("calls_button"))
self.horizontalLayout.addWidget(self.calls_button)
self.vehicles_button = QtGui.QPushButton(self.widget)
self.vehicles_button.setCheckable(True)
self.vehicles_button.setObjectName(_fromUtf8("vehicles_button"))
self.horizontalLayout.addWidget(self.vehicles_button)
self.persons_button = QtGui.QPushButton(self.widget)
self.persons_button.setCheckable(True)
self.persons_button.setObjectName(_fromUtf8("persons_button"))
self.horizontalLayout.addWidget(self.persons_button)
self.pushButton_6 = QtGui.QPushButton(self.widget)
self.pushButton_6.setCheckable(True)
self.pushButton_6.setObjectName(_fromUtf8("pushButton_6"))
self.horizontalLayout.addWidget(self.pushButton_6)
self.pushButton_4 = QtGui.QPushButton(self.widget)
self.pushButton_4.setCheckable(True)
self.pushButton_4.setObjectName(_fromUtf8("pushButton_4"))
self.horizontalLayout.addWidget(self.pushButton_4)
self.pushButton_5 = QtGui.QPushButton(self.widget)
self.pushButton_5.setCheckable(True)
self.pushButton_5.setObjectName(_fromUtf8("pushButton_5"))
self.horizontalLayout.addWidget(self.pushButton_5)
self.verticalLayout.addLayout(self.horizontalLayout)
self.inserted_module = QtGui.QWidget(self.widget)
self.inserted_module.setMinimumSize(QtCore.QSize(481, 321))
self.inserted_module.setObjectName(_fromUtf8("inserted_module"))
self.verticalLayout.addWidget(self.inserted_module)
Dashboard.setCentralWidget(self.centralwidget)
self.menubar = QtGui.QMenuBar(Dashboard)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 23))
self.menubar.setObjectName(_fromUtf8("menubar"))
Dashboard.setMenuBar(self.menubar)
self.statusbar = QtGui.QStatusBar(Dashboard)
self.statusbar.setObjectName(_fromUtf8("statusbar"))
Dashboard.setStatusBar(self.statusbar)
self.retranslateUi(Dashboard)
QtCore.QMetaObject.connectSlotsByName(Dashboard)
def retranslateUi(self, Dashboard):
Dashboard.setWindowTitle(_translate("Dashboard", "MainWindow", None))
self.units_button.setText(_translate("Dashboard", "Units", None))
self.calls_button.setText(_translate("Dashboard", "Calls", None))
self.vehicles_button.setText(_translate("Dashboard", "Vehicles", None))
self.persons_button.setText(_translate("Dashboard", "Persons", None))
self.pushButton_6.setText(_translate("Dashboard", "PushButton", None))
self.pushButton_4.setText(_translate("Dashboard", "PushButton", None))
self.pushButton_5.setText(_translate("Dashboard", "PushButton", None))
main.py
import sys
from PyQt4 import QtCore, QtGui, uic
from dashboard import Ui_Dashboard
class MainWindow(QtGui.QMainWindow, Ui_Dashboard):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.units_table = uic.loadUi('units_table.ui', self)
self.inserted_module = self.units_table
self.inserted_module.setMinimumSize(QtCore.QSize(481, 321))
self.verticalLayout.addWidget(self.inserted_module)
self.setupUi(self)
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec_()
I'm able to display the imported widget perfectly fine, but I need to add it as a child to the vertical layout, which is where I'm having difficulties. Despite Ui_Dashboard being inherited, I still can't access the verticalLayout.
I keep getting the following error:
AttributeError: 'MainWindow' object has no attribute 'verticalLayout'
verticalLayout does not exist because it is created in the setupUi() method, what you must do is load it before you want to use it. Another mistake is that you should not pass self to loadUi(), since what you will do is reimplement the widget's design:
import sys
from PyQt4 import QtCore, QtGui, uic
from dashboard import Ui_Dashboard
class MainWindow(QtGui.QMainWindow, Ui_Dashboard):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.setupUi(self)
self.units_table = uic.loadUi('units_table.ui')
self.verticalLayout.addWidget(self.units_table )
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())
So i am just starting out using Qt4 and pyqt to convert the code to python and so on. I am trying to create a timer of sorts but that doesn't really matter. I've created the gui in Qt and converted it to python code, added a few things to get the code running, but when i run it i still just get a blank window, none of the buttons of boxes that i created are showing up. any ideas??
thanks
import sys
import time
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_Dialog(QtGui.QWidget):
def _init_(self):
QtGui.QWidget.__init__(self)
self.setupUi(self)
def setupUi(self, Dialog):
Dialog.setObjectName(_fromUtf8("Dialog"))
Dialog.resize(160, 183)
self.gridLayout = QtGui.QGridLayout(Dialog)
self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
self.countInput = QtGui.QLineEdit(Dialog)
self.countInput.setObjectName(_fromUtf8("countInput"))
self.gridLayout.addWidget(self.countInput, 2, 0, 1, 1)
self.timeView = QtGui.QLCDNumber(Dialog)
self.timeView.setInputMethodHints(QtCore.Qt.ImhDigitsOnly)
self.timeView.setDigitCount(5)
self.timeView.setObjectName(_fromUtf8("timeView"))
self.gridLayout.addWidget(self.timeView, 2, 1, 1, 1)
self.startButton = QtGui.QPushButton(Dialog)
self.startButton.setObjectName(_fromUtf8("startButton"))
self.gridLayout.addWidget(self.startButton, 3, 0, 1, 1)
self.stopButton = QtGui.QPushButton(Dialog)
self.stopButton.setAutoDefault(True)
self.stopButton.setDefault(True)
self.stopButton.setObjectName(_fromUtf8("stopButton"))
self.gridLayout.addWidget(self.stopButton, 3, 1, 1, 1)
self.progressLbl = QtGui.QLabel(Dialog)
self.progressLbl.setText(_fromUtf8(""))
self.progressLbl.setAlignment(QtCore.Qt.AlignCenter)
self.progressLbl.setObjectName(_fromUtf8("progressLbl"))
self.gridLayout.addWidget(self.progressLbl, 4, 0, 1, 2)
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
Dialog.setWindowTitle(_translate("Dialog", "Dialog", None))
self.startButton.setText(_translate("Dialog", "Start", None))
self.stopButton.setText(_translate("Dialog", "Stop", None))
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
ex = Ui_Dialog()
ex.show()
sys.exit(app.exec_())
def _init_(self):
QtGui.QWidget.__init__(self)
self.setupUi(self)
You are missing the double underscores for the init, so yours isn't getting called.
It should be:
def __init__(self):
QtGui.QWidget.__init__(self)
self.setupUi(self)
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))