QPushButton clicked connect strange behavior
-
Hello,
Got the following code:
class NoteManagerClass(QMainWindow): def __init__(self): super().__init__() # Widgets newNoteButton = QPushButton("New Note") newNoteButton.clicked.connect(self.newNote()) # This actually calls the newNote() function . . more lines . def newNote(self): print("New Note")
The problem: when the script reaches the button connect function, it executes the newNote function, but later, when the button is clicked, that function isn't called. Not sure whats going on.
(Sorry in advance for possibly stupid question, newbie in both Qt and python)
TIA
-
Hello,
Got the following code:
class NoteManagerClass(QMainWindow): def __init__(self): super().__init__() # Widgets newNoteButton = QPushButton("New Note") newNoteButton.clicked.connect(self.newNote()) # This actually calls the newNote() function . . more lines . def newNote(self): print("New Note")
The problem: when the script reaches the button connect function, it executes the newNote function, but later, when the button is clicked, that function isn't called. Not sure whats going on.
(Sorry in advance for possibly stupid question, newbie in both Qt and python)
TIA
This actually calls the newNote() function
Yes, because you called it (used the
()
operator). You're supposed to pass the function address, not call it i.e.newNoteButton.clicked.connect(self.newNote)
-
-
This actually calls the newNote() function
Yes, because you called it (used the
()
operator). You're supposed to pass the function address, not call it i.e.newNoteButton.clicked.connect(self.newNote)
@Chris-Kawa said in QPushButton clicked connect strange behavior:
This actually calls the newNote() function
Yes, because you called it (used the
()
operator). You're supposed to pass the function address, not call it i.e.newNoteButton.clicked.connect(self.newNote)
Right, it works now. Thanks a bunch.