Random QColor Generator

  • Share this:

Code introduction


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


Technology Stack : PyQt5, random, randint

Code Type : Function

Code Difficulty : Intermediate


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

    def random_int(min_val, max_val):
        return randint(min_val, max_val)

    red = random_int(0, 255)
    green = random_int(0, 255)
    blue = random_int(0, 255)
    return QColor(red, green, blue)