Random Color Selection from QColor List

  • Share this:

Code introduction


This function randomly selects a color name from the QColor color name list in the PyQt5.QtGui module and returns the name of the color.


Technology Stack : PyQt5.QtGui

Code Type : Custom function

Code Difficulty : Intermediate


                
                    
def select_random_color():
    import random
    from PyQt5.QtGui import QColor

    colors = ["red", "green", "blue", "yellow", "purple", "orange"]
    color_name = random.choice(colors)
    color = QColor(color_name)
    return color.name()                
              
Tags: