所以,这是一个小游戏代码的开始。目的是化解最接近0的3枚炸弹。我已经成功创造了窗户,进行倒计时......但我不知道如何设置按钮来停止倒计时。如果有人可以帮助我,那几天我一直在寻找解决方案:(
import time, os
from Tkinter import *
from math import *
import random
#####################################################
def new():
fenetre.destroy()
我们将专注于那部分
def decompte(label, count=10):
label.config(text="{:.2f}".format(count))
if count > 0 :
fen1.after(10,decompte, *(label, count-0.01))
def stopper():
fen1=Tk()
fen1.geometry("500x500")
lab=Label(fen1, text="")
lab.pack()
lab1=Label(fen1, text="")
lab1.pack()
lab2=Label(fen1, text="")
lab2.pack()
lab3=Label(fen1,text="")
lab3.place(x=300,y=200)
x=(random.randint(3,4))
y=(random.randint(5,6))
z=(random.randint(6,7))
decompte(lab, x)
decompte(lab2, y)
decompte(lab3,z)
btn1=Button(fen1, text="stop", command=stopper)
btn1.pack()
btn3=Button(fen1, text="quit",command=fen1.destroy)
btn3.pack()
lab.place(x=100,y=200)
lab1.place(x=150,y=200)
lab2.place(x=200,y=200)
fen1.mainloop()
######################################################
fenetre= Tk()
fenetre.configure(bg="black")
fenetre.geometry("1024x620")
canvas= Canvas(fenetre, width=1024, height=620,bg="black")
canvas.grid(row=0, column=0)
photo = PhotoImage(file="demineur.gif")
canvas.create_image(512,310, image=photo)
btn= Button(fenetre, text="JOUER",bg="yellow",command=new)
btn.place(x=240,y=500)
fenetre.mainloop()
答案 0 :(得分:0)
countdown = True
def decompte(label, count=10):
label.config(text="{:.2f}".format(count))
if count > 0 and countdown: # <- global variable `countdown`
fen1.after(10,decompte, *(label, count-0.01))
def stopper():
global countdown
countdown = False