mardi 28 février 2023

How to have a string thats constantly changing change into a set word one letter at a time

The label is printing a 5 letter word, consisting of random letters, every 10,000th of a second it changes creating a constanly changing random bunch of letters. I want to be able to make each index of the word(which is randomly changing), change into a letter from a word of my choice, with a delay between each letter updating so that while the index[0] has become the first letter of my selected word, the other index's are still 'scrambling', then index[1] becomes the second letter of the word, and so on.

letters = string.ascii_letters
text = "Dylan"
word= list(text)
index=0

def loop():
    loop1()
    loop2()
    loop3()
    loop4()
    loop5()
    window.after(1, loop)

count=0

def loop1():
    global word, letters, index, wordlist,count
    if count < 1:
        word[0] = random.choice(letters)
        label.config(text=word)


def loop2():
    global word, letters, index, wordlist,count
    if count < 2:
        word[1] = random.choice(letters)
        label.config(text=word)

    
def loop3():
    global word, letters, index, wordlist,count
    if count < 3:
        word[2] = random.choice(letters)
        label.config(text=word)


def loop4():
    global word, letters, index, wordlist,count
    if count < 4:
        word[3] = random.choice(letters)
        label.config(text=word)


def loop5():
    global word, letters, index, wordlist,count
    if count < 5:
        word[4] = random.choice(letters)
        label.config(text=word)


def dejumble(event):
    global stopvar, count
    for i in range(5):
        count+=1
        print(count)
        unscramble()

def update_label():
     label.config(text=wordlist)

    
index1=0

def unscramble():
    window.after(1000, update_label)
    global index1
    global wordlist, word
    print(text[index1])
    word[index1] = text[index1]
    window.after(1000, config)
    index1  += 1
    print(word)

def config():
    label.config(text=word)    
    
def looped(event):
    loop()
      

I tried the above code but instead of unscrambling one at a time, it pauses on the last list of random letters, then updates all at once. Based on the prints I think its the label not updating correctly and not the unscrambling bit.




Aucun commentaire:

Enregistrer un commentaire