Random Hex Color Generator App

  • Share this:

Code introduction


The function creates a simple Textual application that generates a random hexadecimal color code and displays it in the application.


Technology Stack : Textual, Random number generation

Code Type : Function

Code Difficulty : Intermediate


                
                    
def random_color_hex():
    import random
    import textual

    def get_random_color():
        return f'#{random.randint(0, 0xFFFFFF):06x}'

    app = textual.App()
    color = get_random_color()
    app.print(f"Your random color is: {color}")
    app.run()