0

I'm following Tech With Tim's tutorial on PyQt5 Video Link

I'm using PyCharm for this. Here's My Current Code

from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QApplication, QMainWindow
import sys


class MyWindow(QMainWindow):
    def __init__(self):
        super(MyWindow, self).__init__()

        self.setGeometry(200, 200, 500, 500)
        self.setWindowTitle("Data")
        self.initUI()

    def initUI(self):
        self.label1 = QtWidgets.QLabel(self)
        self.label1.setText("Hello World")
        self.label1.move(225, 250)

        self.button1 =QtWidgets.QPushButton(self)
        self.button1.setText("Click Me")
        self.button1.move(200, 200)
        self.button1.clicked.connect(self.pressed())

    def pressed(self):
        self.label1.setText("You Clicked")


def window():
    app = QApplication(sys.argv)
    win = MyWindow()
    win.show()
    sys.exit(app.exec_())


window()

I get a problem that says "Cannot find reference 'connect' in 'function' " Of course I first tried searching google but they revolve around PyQt4 which I assumed won't answer my problem.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
codeBit
  • 84
  • 2
  • 10
  • Please provide the full error message including the traceback. – Niklas Mertsch Oct 23 '20 at 18:06
  • 1
    change `self.button1.clicked.connect(self.pressed())` to `self.button1.clicked.connect(self.pressed)` – S. Nick Oct 23 '20 at 18:10
  • Your code gives me a different error: `self.button1.clicked.connect(self.pressed()): TypeError: argument 1 has unexpected type 'NoneType'`. This can be resolved by using `.connect(self.pressed)` (without parentheses), and then it runs fine on my machine. – Niklas Mertsch Oct 23 '20 at 18:11
  • 1
    1) You must make the change that they have indicated, 2) the warning that you indicate only evidence of a bug in your IDE (most likely pycharm) is not capable of recognizing methods created in C++, I recommend you ignore that warning – eyllanesc Oct 23 '20 at 18:14

0 Answers0