簡體   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