语法def python 3.5.2无效

2024-06-14 07:08:10 发布

您现在位置:Python中文网/ 问答频道 /正文

请帮我解决不了这个问题。我正在尝试像素搜索。使用python3.5.2时,当试图从Shell运行它时,def上出现语法错误。在

import ImageGrab
import os
import time
import win32api, win32con


# Globals
# ------------------

x_pad = 464
y_pad = 244

def screenGrab():
    box = (x_pad+1, y_pad+1, x_pad+639, y_pad+477)
    im = ImageGrab.grab(box)
    im.save(os.getcwd() + '\\full_snap__' + str(int(time.time())) +
('.png', 'PNG')

def leftClick():
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0)
    time.sleep(.1)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)
    print ("Click.") #completely optional. But nice for debugging purposes.

def leftDown():
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0)
    time.sleep(.1)
    print ('left Down')

def leftUp():
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)
    time.sleep(.1)
    print ('left release')


def mousePos(cord):
    win32api.SetCursorPos((x_pad + cord[0], y_pad + cord[1])

def get_cords():
    x,y = win32api.GetCursorPos():
    x = x - x_pad
    y = y - y_pad
    print (x,y)

def main():
    pass

if __name__ == '__main__':
    main()

我不熟悉编程,所以非常感谢任何帮助。在


Tags: importeventtimeosmaindefsleepprint