why x still undefined?
from tkinter import * z= {'black':1, 'red':2,'yellow':3,'blue':4,'red':5} co=list(z) v=[] ls=[] w = Tk() g=Label(w,text=' ',width=10,height=5) g.pack() c=0 def f(): global x global c m=co[c%len(co)] g.config(bg=m) a=z.get(m) v.append(str(a)) w.after(1000,f) c+=1 if c==5 : g.pack_forget() x=''.join(v) f() b1=Button(w,text='',width=8,height=5,bg='black',command=lambda:ls.append(1)).pack(side=LEFT) b2=Button(w,text='',width=8,height=5,bg='red',command=lambda:ls.append(2)).pack(side=LEFT) b3=Button(w,text='',width=8,height=5,bg='yellow',command=lambda:ls.append(3)).pack(side=LEFT) b4=Button(w,text='',width=8,height=5,bg='blue',command=lambda:ls.append(4)).pack(side=LEFT) def check(): global x if ls==x: print(x) Button(w,text='check',command=check).pack() w.mainloop()