Skip to content

Instantly share code, notes, and snippets.

@PaulleDemon
Last active October 26, 2021 13:27
Show Gist options
  • Save PaulleDemon/7dcdf3300cdd967c00a3b3219f1f04f8 to your computer and use it in GitHub Desktop.
Save PaulleDemon/7dcdf3300cdd967c00a3b3219f1f04f8 to your computer and use it in GitHub Desktop.
This is an example of signal and slot in pyqt
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QPushButton, QVBoxLayout
def change_button_text():
button.setText("Button has been clicked")
if __name__ == '__main__':
app = QApplication(sys.argv)
widget = QWidget()
v_layout = QVBoxLayout()
label = QLabel("Sample label")
button = QPushButton("Button")
button.clicked.connect(change_button_text) # The clicked is the signal and you will connect it to a slot using connect method
v_layout.addWidget(label)
v_layout.addWidget(button)
widget.setLayout(v_layout)
widget.show()
sys.exit(app.exec())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment