So I am trying to make hangman in python using Tkinter and I have mostly finished the game but, I want to add a feature that disables the button once it is pressed so that the user doesn't guess the same letter twice. Any idea how I can implement it.
the code:https://drive.google.com/file/d/1v0tjlSZC_xHCQ0WopNPRJC1pLNaQ4wRR/view?usp=sharing
Not only do you overwrite the button
object when you create all the buttons, the button
object will also be None
because place()
doesn't return anything. Split that line in two:
button = Button(...) and
button.place(...)
But even then the button object is overwritten for each new button, so the button object takes the value of the last button 'z'.
To disable individual buttons, you need to be able to access each of them, eg by putting all objects in a list: button[n] = Button(...)
Then in the guess()
function you must disable exactly that button that was pressed.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.