想要tkinter里的标签不停变换列表中的颜色,这是错误代码:
import tkinter as tk
import time
def colored():
for i in reds:
label1.config(text=i,fg=i)
time.sleep(1)
tk_main.after(1000,colored)
reds=['IndianRed',
'LightCoral',
'Salmon',
'DarkSalmon',
'LightSalmon',
'Crimson',
'Red',
'FireBrick',
'Pink',
'LightPink',
'HotPink',
'DeepPink',
'PaleVioletRed']
tk_main = tk.Tk()
tk_main.geometry('400x300')
label1=tk.Label(tk_main,text = '颜色测试',font = ('宋体',35,'bold'))
label1.pack(expand = 1)
colored()
tk_main.mainloop()
结果不尽人意,卡的窗口都不会出现了。