I am trying to make a graphical slot machine and am currently working on trying to make the slots "spin". However the buttons seem to skip all other changes and go straight to the final value. I have tried using time.sleep but this too doesn't work. Currently I am looping through a second function but still does not work. How can I ensure the buttons show all values they have taken throughout the looping process?
Here is the code below:
import tkinter as tk,random,time
root=tk.Tk()
results=["@","!","$","W","*","£","#","X","%"]
class spin:
def __init__(self,rowa,columna,text):
self.text=text
self=tk.Button(root, height=1,width=2,text=text)
self.grid(row=rowa,column=columna)
class spun:
def __init__(self,rowa,columna,text,com):
self.text=text
self=tk.Button(root, height=1,width=15,text=self.text,command=com)
self.grid(row=rowa,column=columna, columnspan=5)
def rotate():
for i in range(0,10):
part2()
time.sleep(0.00005)
def part2():
global slot1,slot2,slot3,slot4,slot5
slot1=spin(1,0,results[random.randint(0,len(results)-1)])
slot2=spin(1,1,results[random.randint(0,len(results)-1)])
slot3=spin(1,2,results[random.randint(0,len(results)-1)])
slot4=spin(1,3,results[random.randint(0,len(results)-1)])
slot5=spin(1,4,results[random.randint(0,len(results)-1)])
slot1=spin(1,0,"@")
slot2=spin(1,1,"£")
slot3=spin(1,2,"%")
slot4=spin(1,3,"$")
slot5=spin(1,4,"#")
spinner=spun(2,0,"Spin",rotate)
root.mainloop()