Random Color Selection Function

  • Share this:

Code introduction


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()