Karim.k
Karim.k

Reputation: 19

Button that changes a boolean value tkinter

I have a button in Tkinter that acts as the first button in a game so I want it to start the game and also destroy itself so the player can start playing, but I can't seem to get it to work.

Here is my code so far, any help would be much appreciated:

from tkinter import *
from random import seed
from random import randint
from tkinter import font as font
import time

root = Tk()
myFont = font.Font(size=25)
root.title("Python Guessing Game")
root.geometry("600x600")

ready = False;


if ready == True:
  print('Hello! What is your name ?')
  destroyBtn()



button_start = Button(root, text="Start Game", font=myFont, bg='#0052cc', fg='#ffffff', command=ready 
   = True, height=1, width=20).place(relx=0.5, rely=0.5, anchor=CENTER)

def destroyBtn():
   button_start.destroy()

Upvotes: 0

Views: 3252

Answers (1)

Brett La Pierre
Brett La Pierre

Reputation: 533

Hello I've coded a quick sample of what I believe you are looking for. If this does not solve this issue please expand on what you are looking for.

from tkinter import *

gameStarted = False

def startGame():
    gameStarted = True
    print("The game status is now:" + str(gameStarted))
    myButton.destroy()
    print("The button is now destroyed.")


root = Tk()
myButton = Button(root, text="start game", command=startGame)
myButton.pack(fill=BOTH)
root.mainloop()

Upvotes: 2

Related Questions