Last active
October 26, 2021 13:27
-
-
Save PaulleDemon/7dcdf3300cdd967c00a3b3219f1f04f8 to your computer and use it in GitHub Desktop.
This is an example of signal and slot in pyqt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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