I want to change the text in a label everytime the button is clicked and the command is called. Here is my code:
Every time the button is clicked, a new label is created under it. How can I make it change the current label based on the rgb_color? Thanks.
Code:
from Tkinter import *
from random import *
def background():
x = randrange(255)
y = randrange(255)
z = randrange(255)
rgb_color = [x,y,z]
mycolor = '#%02x%02x%02x' % (x, y, z)
app.configure(bg=mycolor)
label1 = Label(app, text=rgb_color)
label1.pack()
app = Tk()
app.geometry("500x400+5+5")
app.resizable(0,0)
app.title("Color Code")
button1 = Button(app, text="Change", command=background)
button1.pack()
app.mainloop()
Comment