mercredi 30 janvier 2019

Replace random after count in python 3 with tkinter

I'm creating a 20 questions game which requires a NEW random value to be created for the "answer". I'm having trouble as if I put the randomization OUTSIDE of the command loop, it doesn't change, and if I put it INSIDE it doesn't carry.... Any recommendations? I've deleted all the excess code.

I've tried the random only inside, only outside, and in both, none of which worked. Any other count attempts I've tried have failed. Prior to trying to change the randomizer, everything functioned correctly. I considered trying to add 2 buttons, but it just wasn't what I was looking for...

window = Tk()

window.title("Welcome to LikeGeeks app")
window.geometry('400x200')

answers = ('dog','cat','rock','aki','table','flower','paris','florida', 'jackie chan')
#deleted section of all the string lists start
#deleted section of all the string lists end

aki = Label(window, text="Aki:  ", font=("Tahoma", 14))
aki.grid(column=0, row=0)

sp1 = Label(window, text="Let's play 20 Questions, and you guess first.", fg="blue", font=("Tahoma", 14))
sp1.grid(column=1, row=0, sticky=W)

sp2 = Label(window, text="Try to only say one word answers.", fg="blue", font=("Tahoma", 14))
sp2.grid(column=1, row=1, sticky=W)

sp3 = Label(window, text="If that's alright, type \"okay\"", fg="blue", font=("Tahoma", 14))
sp3.grid(column=1, row=2, sticky=W)

ent = Entry(window,width=15)
ent.grid(column=1, row=3, sticky=W)

#original location of the answertrue = random segment

count = 0
#working that button
def clicked():
    global count
    guess = str(ent.get())
    count = count + 1
    if count == 1:
        sp1.configure(text="Then let's begin!")
        sp2.configure(text="Make your first guess.")
        sp3.configure(text=" ")
        answertrue = random.choice(answers)


#Restart the program
    if count == 20:
        sp1.configure(text="You took too long!")
        sp2.configure(text="Click Sart to choose a new word,")
        sp3.configure(text="or click enter for another 20 guesses!")
        count = 0

    if count == 2:
#this was all the base elifs for seeing if you guessed correctly, it was obnoxiously long, so I deleted it.



btn = Button(window, text="Enter", bg="white", fg="green", command=clicked)
btn.grid(column=0, row=4)

I hope that I can just get it to set back the count to 0 and create a new random value for answertrue from the list answers to come out.




Aucun commentaire:

Enregistrer un commentaire