繁体   English   中英

为什么 time.sleep 不能等待超过 1 分钟?

[英]Why the time.sleep can't wait more then 1 minute?

我正在尝试使用 tkinter 制作一个应用程序,以便在某个时间点在我的桌面上自动单击,我知道 forms 这样做更好,但是使用 Tkinter 到目前为止我只做了这个我快完成了,但时间。睡眠 function 不能等待超过 30 秒,我启动程序然后 Tkinter window 停止工作大约 1 分钟。 我已经尝试过使用 time.wait 但它也发生了同样的事情,我读到 time.sleep 函数接受任何有效数字,为什么会这样?

win = Tk()
win.title('autoclass.enter V1')
win.geometry('500x300')

aroh= Entry(win, width=30)
aroh.place(x=178, y=170)
hora= Entry(win, width=30)
hora.place(x=178, y=100)
aahg = datetime.now()

def chronus():
    MB = int(aroh.get())
    HB1 = int(hora.get())
    HB = HB1 * 60
    won = aahg.time().strftime('%H:%M')
    own = str(won)
    nwo = own.split(':')
    xa,xo = nwo[0],nwo[1]
    HA1 = int(xa)
    MA = int(xo)
    HA = HA1 * 60
    print(HA)
    print(MA)
    M1 =(HA + MA)
    M2 =(MB + HB)
    print(M1/60)
    print(M2/60)
    M3 = M2 - M1
    print('M1=', M1)
    print('M2=', M2)
    if M3 < 0:
        M4 = (M2 - M1) + 1440
        print('M4=', M4)
        M4I = M4 * 60
        time.sleep(M4I)             #here is the time.sleep problem
        pyautogui.click(100, 100)
        time.sleep(1)
        pyautogui.moveTo(200, 200, duration = 1) 
        pyautogui.click(200, 200)
    elif M3 > 0:
        print('M3=', M3)
        M3I = M3 * 60
        time.sleep(M3I)              # or here
        pyautogui.click(100, 100)
        time.sleep(1)
        pyautogui.moveTo(200, 200, duration = 1) 
        pyautogui.click(200, 200)

myLabel6 = Label(win, text='hout that it is going to work')
myLabel6.place(x=195, y=78)
button = Button(win, text='start', command=chronus)
button.place(x=50, y=80)
win.mainloop() 

Tkinter window 停止工作约 1 分钟,它什么也不做。

time.sleep 将使程序正在运行的线程休眠。 所以它阻止了你的程序。

检查以下答案: https://stackoverflow.com/a/19887761/908893

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM