PyQt5 Button Click to Display Label

  • Share this:

Code introduction


This code creates a PyQt5 application containing a button. When the button is clicked, a label is displayed showing the text 'Button Clicked!'


Technology Stack : PyQt5

Code Type : PyQt5 GUI Application

Code Difficulty : Intermediate


                
                    
import random
from PyQt5.QtWidgets import QApplication, QPushButton, QLabel

def random_button_click():
    app = QApplication([])
    window = QPushButton('Click Me!', parent=None)
    window.clicked.connect(lambda: QLabel('Button Clicked!', parent=None).show())
    window.show()
    app.exec_()                
              
Tags: