dimanche 6 janvier 2019

How can I use a button in Tkinter to stop a different line of code from running?

I am creating a personal project to attempt to get better at python. The game I am making is Yahtzee. I have it setup to where you can roll all of the die and it will tell you what you have. I also have a window setup using Tkinter. What I am trying to do is have a button that says "HOLD" underneath each number. If you know how yahtzee works you would know why. I just want this button to stop that dice from rolling again after your first roll.

I have looked at other posts here on Stack Overflow, but none of the posts are in the way I have been trying to figure out.

# Window
def hold():


window = Tk()
window.title("Sam's Yahtzee")
window.configure(background="black")
Button(window, text="HOLD", width=6, command=hold) .grid(row=3, column=0, 
sticky=W)
window.mainloop()

# Dice Roll
roll1 = random.randint(1, 6)
roll2 = random.randint(1, 6)
roll3 = random.randint(1, 6)
roll4 = random.randint(1, 6)
roll5 = random.randint(1, 6)
print(roll1, roll2, roll3, roll4, roll5)

# Choosing What Num to Hold


# Roll Num Storing
userRollHold = {'roll1': roll1,
            'roll2': roll2,
            'roll3': roll3,
            'roll4': roll4,
            'roll5': roll5}

I am hoping for a button that will be able to stop a number from being rolled again.




Aucun commentaire:

Enregistrer un commentaire