我正在做一个程序,在某个时间自动进入一个网站(我知道这是其他的方法),但这是一个问题,程序没有等到正确的时间,当按下按钮时,它就会自动启动。我试着这样做,像一个警报,许多警报形式,但它总是相同的。我是怎么做这项工作的?谢谢。下面是我正在做的一个简单的例子:
import pynput
from datetime import *
import tkinter
from tkinter import *
import pyautogui
import time
from pynput.keyboard import Key, Controller
win = Tk()
win.title('autoclass.enter V1')
win.geometry('500x300')
hora= Entry(win, width=30)
hora.place(x=178, y=100)
hour = hora.get()
def start():
while(1 == 1):
won = str(datetime.now().time())
now = (won[11:10])
print(now)
if (hour == now):
print(now)
stop = True
pyautogui.click(a, b)
time.sleep(g)
pyautogui.moveTo(c, d, duration = 1)#I had change the numbers by letters to not destroi ur dektop
pyautogui.click(e, f)
keyboard = Controller()
time.sleep(2)
time.sleep(8)
keyboard.type(hello)
keyboard.press(Key.enter)
keyboard.release(Key.enter)
break
myLabel6 = Label(win, text='the hour(like this 7:30')
myLabel6.place(x=195, y=78)
button = Button(win, text='start', command=start)
button.place(x=50, y=80)
win.mainloop()发布于 2020-07-22 02:41:17
您可以使用time模块和while循环来检查当前时间是否等于您想要的时间。
from time import gmtime, strftime
desired_time = '13:28'
while True:
if strftime("%H:%M", gmtime()) == desired_time:
main()但在Tkinter中,while loop将冻结程序。我建议做一个根据那个if语句检查时间的函数
def time_checker():
if strftime("%H:%M", gmtime()) == desired_time:
main()https://stackoverflow.com/questions/63021062
复制相似问题