Cant get program to run correctly Python/Qt/PyQt - python

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)

Related

Cant't hide a window when window size maximized in pyqt

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

Check all QCheckBox in a QtGui.QGridLayout

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

Python - Pyqt: Duplicate output when I use setCurrentIndex

When I press the button for go to a diferent page using setCurrentIndex I have problems with duplicate output values because if I set value "1" on QLineEdit on home_page for example and then go to conf_page and now I back to home_page, when I press the OK button for print content of QLineEdit for example, I get a duplicate output.
My code.
Project.py file.
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(object):
def setupUi(self, Dialog):
Dialog.setObjectName(_fromUtf8("Dialog"))
Dialog.resize(210, 191)
self.frame = QtGui.QFrame(Dialog)
self.frame.setGeometry(QtCore.QRect(0, 0, 211, 61))
self.frame.setFrameShape(QtGui.QFrame.StyledPanel)
self.frame.setFrameShadow(QtGui.QFrame.Raised)
self.frame.setObjectName(_fromUtf8("frame"))
self.pushButton_2 = QtGui.QPushButton(self.frame)
self.pushButton_2.setGeometry(QtCore.QRect(20, 20, 75, 23))
self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
self.pushButton_3 = QtGui.QPushButton(self.frame)
self.pushButton_3.setGeometry(QtCore.QRect(110, 20, 75, 23))
self.pushButton_3.setObjectName(_fromUtf8("pushButton_3"))
self.stackedWidget = QtGui.QStackedWidget(Dialog)
self.stackedWidget.setGeometry(QtCore.QRect(0, 60, 211, 131))
self.stackedWidget.setObjectName(_fromUtf8("stackedWidget"))
self.page = QtGui.QWidget()
self.page.setObjectName(_fromUtf8("page"))
self.lineEdit = QtGui.QLineEdit(self.page)
self.lineEdit.setGeometry(QtCore.QRect(50, 50, 113, 20))
self.lineEdit.setObjectName(_fromUtf8("lineEdit"))
self.pushButton = QtGui.QPushButton(self.page)
self.pushButton.setGeometry(QtCore.QRect(70, 90, 75, 23))
self.pushButton.setObjectName(_fromUtf8("pushButton"))
self.stackedWidget.addWidget(self.page)
self.page_2 = QtGui.QWidget()
self.page_2.setObjectName(_fromUtf8("page_2"))
self.stackedWidget.addWidget(self.page_2)
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
Dialog.setWindowTitle(_translate("Dialog", "Dialog", None))
self.pushButton_2.setText(_translate("Dialog", "PushButton", None))
self.pushButton_3.setText(_translate("Dialog", "PushButton", None))
self.pushButton.setText(_translate("Dialog", "PushButton", None))
Project.pyw file.
from project import *
import sys
class project(QtGui.QDialog):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_Dialog()
self.ui.setupUi(self)
QtCore.QObject.connect(self.ui.pushButton_2, QtCore.SIGNAL('clicked()'), self.home_page)
QtCore.QObject.connect(self.ui.pushButton_3, QtCore.SIGNAL('clicked()'), self.down_page)
def home_page(self):
self.ui.stackedWidget.setCurrentIndex(0)
QtCore.QObject.connect(self.ui.pushButton, QtCore.SIGNAL('clicked()'), self.output)
def down_page(self):
self.ui.stackedWidget.setCurrentIndex(1)
def output(self):
print(self.ui.lineEdit.text())
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp = project()
myapp.show()
sys.exit(app.exec_())
Any sugestions?
Thanks!!

Changing Pixmap image automatically at runtime in PyQt

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.

AttributeError: 'Ui_Form' object has no attribute 'printHam_btn'

I'm started learning QtDesigner (Python) with Qt 4.8.6 and I follow this tutorial:
https://www.youtube.com/watch?v=GLqrzLIIW2E
but it showing me sometimes error in title sometimes AttributeError: 'Ui_Form' object has no attribute 'printHam_btn'. Can someone please tell me what i have to do or fix my code.
Thanks!
I know that this problem is already post in this forum but I can't find out what I have to do in my case.
CODE:
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.verticalLayout_2 = QtGui.QVBoxLayout(Form)
self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2"))
self.verticalLayout = QtGui.QVBoxLayout()
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
self.print_ham = QtGui.QPushButton(Form)
self.print_ham.setObjectName(_fromUtf8("print_ham"))
self.verticalLayout.addWidget(self.print_ham)
self.verticalLayout_2.addLayout(self.verticalLayout)
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
Form.setWindowTitle(_translate("Form", "Super ham", None))
self.print_ham.setText(_translate("Form", "print ham", None))
self.printHam_btn.clicked.connect(self.printHam)
def printHam(self):
print('Ham!')
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
main_window = Ui_Form()
main_window.show()
sys.exit(app.exec_())
The issue is here:
self.printHam_btn.clicked.connect(self.printHam)
You call your QPushButton instance differently, so you would need to change this line to:
self.print_ham.clicked.connect(self.printHam)

Categories