samedi 28 décembre 2019

Shuffling buttons on tkinter GUI

I am building a multiple choice game using Python and tkinter and I need to be able to shuffle the buttons on the GUI so that the position of the button containing the correct answer changes. I have written this code so far but it seems like the same rely value is often taken from the y_list multiple times leading to buttons hiding each other. How is it possible to ensure that each rely value is only taken once?

y_list=[0.2,0.4,0.6,0.8]

def randy():
    xan = random.choice(y_list)
    return xan

y_list.remove(xan)


wordLabel = Label(newWindow, text=all_words_list[randWord])
wordLabel.place(relx=0.49, rely=0.1)
choice1=Button(newWindow, text=all_definitions_list[randDefinition], height=5, width=20)
choice1.place(relx=0.5,rely=randy(), anchor=N)
choice2=Button(newWindow, text="gangsta", height=5, width=20)
choice2.place(relx=0.5, rely=randy(), anchor=N)
choice3=Button(newWindow, text="gangsta", height=5, width=20)
choice3.place(relx=0.5, rely=randy(), anchor=N)
choice4=Button(newWindow, text="gangsta", height=5, width=20)
choice4.place(relx=0.5, rely=randy(), anchor=N)



Aucun commentaire:

Enregistrer un commentaire