Jan-06-2019, 02:39 PM
(This post was last modified: Jan-06-2019, 02:43 PM by Dwimmerlaik.)
Hi,
I've been trying to insert a hexadecimal number in an image made in tkinter, but I just can't seem to get it right. The idea is that a random sized square appears, then the user is asked which color the square should be via a button and finally the color should be inserted. This is what I have thus far:
I've been trying to insert a hexadecimal number in an image made in tkinter, but I just can't seem to get it right. The idea is that a random sized square appears, then the user is asked which color the square should be via a button and finally the color should be inserted. This is what I have thus far:
from tkinter import * import random tk = Tk() canvas = Canvas(tk, width=400,height=400) canvas.pack() def random_sqaure(width, height, fill_color): x1 = random.randrange(width) y1 = random.randrange(height) x2 = random.randrange(x1 + random.randrange(width)) y2 = random.randrange(y1 + random.randrange(height)) canvas.create_rectangle(x1, y1, x2, y2, fill=fill_color) from tkinter.colorchooser import * def getColor(): color = askcolor() print (color) Button(text = 'Choose color', command=getColor).pack() c = getColor() random_square(400, 400, c)Can somebody help fix this or am I going about this the wrong way?