如何在固定时间后自动关闭窗口?

2024-04-25 14:04:11 发布

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

我正在开发一个GUI,它允许用户决定是继续执行脚本还是终止它,但是如果用户在15分钟内没有响应,我想终止窗口并自动继续执行脚本的其余部分。我用过根目录。销毁()在函数中,但它仅在用户有响应时执行。在

import sys      
import Tkinter   
root = Tkinter.Tk()   
"""def countdown(time):   
    if time==10:   
        root.destroy()   
    else:   
        time +=time """ 
def Yes_callback():    
    root.destroy()   
    return()    
def No_callback():    
    root.destroy() #Kills GUI    
    sys.exit("There is an Overnight execution")#Stops script    
    return() # returns to prog    
ask = Tkinter.Label(text="Do you have any overnight task to run?")    
yes_button = Tkinter.Button(root,text="Yes", command = Yes_callback)    
no_button = Tkinter.Button(root, text="No", command = No_callback)    
ask.pack()   
yes_button.pack()    
no_button.pack()    
#countdown(0)    
root.mainloop()

我试过使用倒计时功能,但它不起作用,因为没有用户响应控制就不能进入倒计时功能。我有什么办法可以完成这项任务吗?在


Tags: notext用户脚本timetkinterdefcallback