我正在制作一个程序,以便在特定时间自动进入一个站点(我知道这是更好的方法) 但这是一个问题,程序没有等到正确的时间,它只是在按下按钮时自动启动。我试着像闹钟一样去做,很多闹钟都是一样的。我是如何做这项工作的?谢谢下面是我正在做的一个简单示例:
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()
您可以使用
time
模块和while
循环检查当前时间是否等于所需的时间但在特金特
while loop
将冻结该程序。我建议创建一个函数,根据if
语句检查时间相关问题 更多 >
编程相关推荐