-1

I am tring to make an app with tkinter to click automaticaly on my desktop at a certain hour, I know that it is better forms to do it, but with Tkinter this that I did is the only that worked so far. I am almost finishing but the time.sleep function can't wait more then 30 seconds, I start the program then the Tkinter window stop working for about 1 minute and it doesn't do nothing. I already tried to use time.wait but it hapened the same thing, I read that the time.sleep functions accept any number as valid so why is it happening?

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() 
  • 1
    Please supply the expected [minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). Most of this code is unrelated to the problem you posted. – Prune Aug 05 '20 at 22:41
  • Maybe try using win.after(ms) instead, but you have to pass in a number of milliseconds – AashirOverflow Aug 05 '20 at 22:48
  • 1
    `time.sleep` will sleep as long as you tell it. Have you verified that what you're passing in is what you assume you're passing in? – Bryan Oakley Aug 05 '20 at 23:01

1 Answers1

0

Tkinter window stop working for about 1 minute and it doesn't do nothing.

time.sleep will sleep the thread on which the program is running. So it's blocking your program.

check the following answer: https://stackoverflow.com/a/19887761/908893