Python Forum
Need help displaying random color
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help displaying random color
#1
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,)
Reply
#2
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Photo I need help with a circle random color code and error Vxploit 4 2,955 Mar-21-2021, 07:23 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020