pyQt: radioButton.isChecked() is executed twice - python

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.

Related

progress bar during time unkonwn process in pyqt4

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()

PyQt: Can't access inherited verticalLayout - "object has no attribute"

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_())

Pyqt4 QFileDialog Constructor: what to use as parent parameter?

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))

PyQt “Not responding”

I'm using Selenium with Python. I'm getting a message in widows Python, when the button is clicked:
Not responding in widows Python
I have the following script:
####file:qu
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.resize(800, 600)
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.pushButton = QtGui.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(340, 110, 75, 23))
self.pushButton.setObjectName(_fromUtf8("pushButton"))
self.pushButton_2 = QtGui.QPushButton(self.centralwidget)
self.pushButton_2.setGeometry(QtCore.QRect(324, 200, 111, 23))
self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
self.lineEdit = QtGui.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(390, 240, 151, 20))
self.lineEdit.setObjectName(_fromUtf8("lineEdit"))
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtGui.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 21))
self.menubar.setObjectName(_fromUtf8("menubar"))
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtGui.QStatusBar(MainWindow)
self.statusbar.setObjectName(_fromUtf8("statusbar"))
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
QtCore.QObject.connect(self.pushButton,QtCore.SIGNAL(_fromUtf8("clicked()")), self.log)
QtCore.QObject.connect(self.pushButton_2, QtCore.SIGNAL(_fromUtf8("clicked()")), self.log2)
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow", None))
self.pushButton.setText(_translate("MainWindow", "PushButton", None))
self.pushButton_2.setText(_translate("MainWindow", "PushButton_2", None))
def log(self):############################
from qf import functon
n=functon()
n.log1()
def log2(self):
from qf import functon
n=functon()
n.log3()
###file:qm
# -*- coding: utf-8 -*-
from PyQt4 import QtGui
from PyQt4.QtGui import QApplication
from PyQt4 import QtCore, QtGui
import sys
from qu import Ui_MainWindow
class MainWindow(QtGui.QMainWindow,Ui_MainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp = MainWindow()
myapp.show()
sys.exit(app.exec_())
file:qf
from selenium import webdriver
from PyQt4 import QtCore, QtGui
import sys
from qu import Ui_MainWindow
class functon ():
def __init__(self, parent=None):
self.parent=parent
def log1(self):
browser =webdriver.Firefox()
browser.get( "http://google.com" )
def log3(self):
text =unicode(self.lineEdit.text())
print text
“Not responding” in Python.
Actually, You main GUI is not frozen at all but only for the time log gets executed and returns control to the main GUI, as you are not implementing any sort of threading mechanism in your application.
So as a solution, you need to thread log method to not block your main GUI, using threading module, the following is a generic way, you need to read more about threading:
1 - import threading in your qu.py file
2 - Define this method in qu.py as well:
def launch_Selenium_Thread(self):
t = threading.Thread(target=self.log)
t.start()
3 - Change the connect method of pushButton to:
QtCore.QObject.connect(self.pushButton,QtCore.SIGNAL(_fromUtf8("clicked()")), self.launch_Selenium_Thread)
4 -Add in qf.py log3 method, txt parameter:
def log3(self, txt):
text =unicode(txt)
print text
5 - Finally fix in qu.py log2 method:
def log2(self):
from qf import functon
n=functon()
txt = self.lineEdit.text()
n.log3(txt)

Using simple python script in qt (via QT-designer)

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))

Categories