Python Forum

Full Version: Need help displaying random color
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello everyone,

I know it may be an easy fix but I'm new to programming and I need some help. I am supposed to create a random color and then display that color(this is only a small part of the assignment). I know it is something simple. I have the random r,g,b values for the color, I just don't know how to display it. I am supposed to make the picture 300w x 200h along with the random color.

from random import *
def main():
showInformation("I will now pop up a randomly colored window")
r = randrange(1,24)
g = randrange(1,200)
b = randrange(30,240)
return makeColor (r,g,b)
makeEmptyPicture(300,200,)
step1 pick a GUI package (I suggest tkinter for this, since it's a simple application)
Next (assuming tkinter), create a simple frame
import tkinter as tk
import random


def app(parent):
    frame = tk.Frame(parent, width=400, height=225)
    frame.grid(row=0, column=0)

    # ... add your color code here ...
    frame.config(background="#f1a2b3") # using two hex digits each for red, green, blue (0 - ff) hex same as (0 - 255)
                                       # decimal
    frame.grid_propagate(0)
    
def main():
    root = tk.Tk()
    app(root)
    root.mainloop()

if __name__ == '__main__':
    main()
Now add your code where shown