TypeError:mousePos()只取1个参数(给定2个)

时间:2013-10-21 00:18:29

标签: function python-2.7 typeerror

我一直想弄清楚如何解决这个错误。这是我第一次遇到这样的错误。我在Google上搜索过,但我找不到解决此问题的方法。

Traceback (most recent call last):
File "C:\Users\Parent\Desktop\NEW PROJECT\code testing and practice.py", line 49, in  <module>
print startGame()
File "C:\Users\Parent\Desktop\NEW PROJECT\code testing and practice.py", line 30, in    startGame
mousePos(304, 197)
TypeError: mousePos() takes exactly 1 argument (2 given)


def leftClick():
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0)
time.sleep(.1)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)
print "Click."         

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 startGame():

#location of first menu
mousePos(304, 197)
leftClick()
time.sleep(.1)

#location of second menu
mousePos(338, 394)
leftClick()
time.sleep(.1)

#location of third menu
mousePos(576, 453)
leftClick()
time.sleep(.1)

#location of fourth menu
mousePos(311, 397)
leftClick()
time.sleep(.1)

print startGame()

2 个答案:

答案 0 :(得分:1)

函数mousePos接受一个参数信号线,它看起来像一个元组或一个列表,你给出两个整数参数。试试mousePos((x,y)),x,y是你的位置

答案 1 :(得分:1)

将坐标放在元组中。

mousePos((311, 397))