'PyCharm not recognizing clicked.connect when using PyQt5 [duplicate]
Fairly new to Python and very new to PyQt5. Getting an error message when trying to assign a method to a button. Not sure what I'm doing different compared to everyone else on the internet.
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QApplication, QMainWindow
import sys
class MyWindow(QMainWindow):
def __init__(self):
super(MyWindow, self).__init__()
self.setGeometry(0, 0, 720, 500)
self.setWindowTitle("PQ Visualizer")
self.initUI()
def initUI(self):
self.label = QtWidgets.QLabel(self)
self.label.setText("Label 1")
self.label.move(50, 50)
self.b1 = QtWidgets.QPushButton(self)
self.b1.setText("Button 1")
self.b1.clicked.connect(self.clicked())
def clicked(self):
self.label.setText("You pressed the button.")
def window():
app = QApplication(sys.argv)
win = MyWindow()
win.show()
sys.exit(app.exec_())
window()

Trying to assign a simple function to a QPushButton
Solution 1:[1]
You are supposed to pass the function, not call it, so remove the ():
self.b1.clicked.connect(self.clicked())
should be
self.b1.clicked.connect(self.clicked)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | DeepSpace |
