更改布尔值tkinter的按钮

2024-09-30 22:19:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我在Tkinter中有一个按钮,作为游戏中的第一个按钮,所以我想让它启动游戏,同时破坏自己,这样玩家就可以开始玩了,但我似乎无法让它工作。

这是我迄今为止的代码,非常感谢您的帮助:

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()

Tags: fromimportgametrue游戏tkinterbuttonrandom
1条回答
网友
1楼 · 发布于 2024-09-30 22:19:21

您好,我已经编写了一个我相信您正在寻找的快速示例。如果这不能解决这个问题,请扩大你正在寻找的

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()

相关问题 更多 >