【发布时间】:2014-01-30 09:10:14
【问题描述】:
import sys
import time
from tkinter import *
from tkinter import messagebox
Gui = Tk()
Gui.title("Exercise Timer")
def jesse(derp):
x=derp
test = 0
while x>=0 and x<=derp:
if test == 0:
Gui.after(1000,makeLabel(x))
x= x-1
if x==0:
test = 1
if test == 1:
if x == 0:
Gui.after(1000,makeLabel("brk pls"))
x=x+1
else:
Gui.after(1000,makeLabel(x))
x=x+1
def makeLabel(texts):
Gui.update()
newlab = Label(text=texts).pack()
def stop():
Gui.destroy()
mbutton = Button(text="10 seconds",command = lambda: jesse(10)).pack()
mbutton = Button(text="20 seconds",command = lambda: jesse(20)).pack()
mbutton = Button(text="30 seconds",command = lambda: jesse(30)).pack()
mbutton = Button(text="quit",fg="red",command = lambda: stop()).pack()
Gui.mainloop()
sys.exit()
对不起,如果这是一个愚蠢的问题,我刚刚开始接触 Python。基本上我的程序是从一个数字开始倒数,然后每 1 秒显示下一个数字。除了我关闭它时,一切都很好。它关闭了,但函数 jesse() 继续运行,出现错误后会弹出一个窗口,上面只有下一个数字,即使我点击了退出按钮或 windows x 按钮。
【问题讨论】:
标签: python user-interface tkinter python-idle