【问题标题】:My autoclicker using python3 and pyautogui isn't working我使用 python3 和 pyautogui 的自动点击器不起作用
【发布时间】:2021-10-16 04:16:44
【问题描述】:

我正在尝试使用 python3 pyautogui 制作一个基本的自动点击器,它允许您选择点击位置的坐标,但它不起作用代码说没有问题但是当我运行它时它会给出错误消息我才开始编码昨天所以它可能是一些简单的修复但我现在不知所措我试图自己制作代码所以我没有遵循一个有任何故障排除的教程所以我无法调查我将它编码在哪里它要求 x 线然后 y 并等待 5 秒并使用两个输入单击坐标指定实际发生的位置它工作直到 5 秒后弹出一堆东西并停止这是代码:

import time
import pyautogui


print ('Please enter X coordinate')
x = input()

print('Please enter Y coordinate')
y = input()

print ('Your coordinates are now"',x,'',y,'"clicking  will begin in five seconds')

time.sleep(1)
print('4')
time.sleep(1)
print('3')
time.sleep(1)
print('2')
time.sleep(1)
print('1')
time.sleep(1)
print('clicking has begun')

def click():
    pyautogui.leftClick(x,y)

while True:
    click()

【问题讨论】:

  • 哎呀忘了提我正在使用 mac osx 10.14 Mojave,如果这很重要的话
  • 我对pyautogui不熟悉,但可能需要将坐标转换为整数,像这样:x = int(input()),和y一样

标签: python-3.x pyautogui


【解决方案1】:

当你使用 :(我们知道 Python 内置的 input() 函数总是返回一个 str(string) 类对象)

x = input() ----> type(x):<class 'str'> string
x =int(input())---->type(x):<class 'int'> integer

因此,为了获取整数输入,我们必须使用 Python 内置的 int() 函数将这些输入类型转换为整数。(例如:int(input())

为您的代码使用这个:

import time
import pyautogui


print ('Please enter X coordinate')
x = int(input())

print('Please enter Y coordinate')
y = int(input())

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-24
    • 1970-01-01
    • 2021-04-03
    • 2014-11-20
    • 2021-04-18
    相关资源
    最近更新 更多