Python GUI更新有一些麻烦


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()持续下去,在错误之后,即使我单击了Quit按钮或Windows X按钮,窗口就会弹出一个窗口。

"

import sys
import time
from Tkinter import *
import tkMessageBox
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):
    try:
        Gui.update()
        newlab = Label(text=texts).pack()
    except TclError:
        pass
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()

"

我添加了一个尝试,除了块以外,它不再给出错误,我知道这不是一个很整洁的修复程序,但我不清楚为什么您的代码甚至会出现错误。我希望如果不

,这会有所抱歉

最新更新