You can download this code by clicking the button below.
This code is now available for download.
Create a button with a random background color. When the user clicks the button, the background color will change.
Technology Stack : PyQt5, QPushButton, QApplication, QColor
Code Type : PyQt5 GUI Application
Code Difficulty : Intermediate
def random_color_button():
from PyQt5.QtWidgets import QPushButton, QApplication
from PyQt5.QtGui import QColor
app = QApplication([])
button = QPushButton("Click Me!")
button.setStyleSheet(f"background-color: {QColor().name()}")
button.show()
app.exec_()