Random Color Generator Function

  • Share this:

Code introduction


This function generates a random color and returns a QColor object.


Technology Stack : PyQt5, QColor

Code Type : Function

Code Difficulty : Intermediate


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

    # Generate a random color using RGB values
    r = random.randint(0, 255)
    g = random.randint(0, 255)
    b = random.randint(0, 255)
    return QColor(r, g, b)                
              
Tags: