Python Forum
TypeError when using PushButton (PyQt5)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TypeError when using PushButton (PyQt5)
#1
I have the following code:

from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from gui import Ui_mainWindow
import acquisition 

class Logic(QtWidgets.QMainWindow, Ui_mainWindow):
    def __init__(self, *args, **kwargs):
        super(Logic, self).__init__(*args, **kwargs)
        self.setupUi(self)
        ###SIGNALS###
        self.actionExit.triggered.connect(self.closeEvent)
        self.actionExit_2.triggered.connect(self.closeEvent)
        self.startScan.clicked.connect(self.startScan)
        self.show()
    def closeEvent(self, event):
        buttonReply = QtWidgets.QMessageBox.question(self, "Exit", "Are you sure want to quit?",
                QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.No)
        if buttonReply == QtWidgets.QMessageBox.Yes:
            sys.exit(app.exec_())
        else:
            event.ignore()

    def startScan(self):
        acquisition.main()

if __name__ == "__main__":
    app = QApplication([])
    app.setApplicationName("xxxx")
    window = Logic()
    app.exec_()
Which returns:
TypeError: argument 1 has unexpected type 'QPushButton'
whenever ran. I have read that using
self.startScan.clicked.connect(lambda:self.startScan)
can alleviate some of these TypeErrors, but for me, the program will simply close if I use the startScan pushbutton.

acquisition.main() returns a matplotlib plot of some data from an oscilloscope. This plot appears perfectly fine when acquisition.main() is called in any other way.

How can I fix this?

Doh! There was a naming error. Problem solved.
        self.startScan.clicked.connect(self.startScan)
Should be:
        self.startScan.clicked.connect(self.beginScan)
and the startScan(self) function should be renamed to beginScan(self)
Reply
#2
sys.exit(app.exec_())
As the app is executed only once, this line should only appear at the end of your program (instead of app.exec_()). To override the closeEvent, use event.accept() instead.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGUI] Pushbutton in ANSA Aishaf 2 2,566 Apr-27-2021, 11:22 AM
Last Post: Aishaf
  [PyQt] pushbutton with image issac_n 1 1,738 Jul-13-2020, 05:04 PM
Last Post: Knight18
  [PyQt] Add command to PushButton skaailet 1 1,659 Apr-11-2020, 01:46 PM
Last Post: deanhystad
  Huge code problems (buttons(PyQt5),PyQt5 Threads, Windows etc) ZenWoR 0 2,785 Apr-06-2019, 11:15 PM
Last Post: ZenWoR
  pyqt clickable pushbutton problem pythonck 1 7,593 Dec-12-2017, 03:38 PM
Last Post: pythonck
  keeping track of pushbutton click iFunKtion 3 4,211 Mar-13-2017, 12:18 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020