You can download this code by clicking the button below.
This code is now available for download.
This function randomly selects a color from a predefined list and returns its name.
Technology Stack : PyQt5.QtGui, QColor, random
Code Type : Function
Code Difficulty : Intermediate
def select_random_color():
from PyQt5.QtGui import QColor
import random
colors = ['red', 'green', 'blue', 'yellow', 'purple', 'orange', 'black', 'white']
color = QColor(random.choice(colors))
return color.name()