如何更改Tkinter中标签的值
我想在每次单击按钮并调用命令时更改标签中的文本。以下是我的代码:
选择 | 换行 | 行号
- 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()
每次单击该按钮时,都会在该按钮下创建一个新标签。如何使其根据RGB_COLOR更改当前标签?谢谢。