我只是想制作一个程序来执行一些键盘输入。我想在每次击键之间设置一个延迟,我计划在将来随机设置。
但是,我不确定如何after()与 Tkinter 一起使用。没有 Tkinter,time.sleep工作正常 - 但有了它,GUI 崩溃了。
任何帮助,将不胜感激。
import time
import tkinter as tk
from pynput.keyboard import Key, Controller as KeyboardController
from pynput.mouse import Button, Controller as MouseController
keyboard = KeyboardController()
mouse = MouseController()
def copy(a):
pause_input=17
pause_input2=2
pause_input3=0.5
x=1
while a >= x:
x = x+1
time.sleep(pause_input)
keyboard.press('t')
keyboard.release('t')
time.sleep(pause_input3)
keyboard.press('e')
keyboard.release('e')
time.sleep(pause_input3)
keyboard.press('s')
keyboard.release('s')
keyboard.press('t')
keyboard.release('t')
root = tk.Tk()
root.title("GUI Button")
btn1 = tk.Button(root, text="Button 1", command=lambda : copy(360))
btn2 = tk.Button(root, text="Button 2")
btn1.pack()
btn2.pack()
root.mainloop()
MYYA
相关分类