我一直在想弄清楚如何解決這個錯誤。這是我第一次碰到這樣的錯誤。我搜遍了谷歌,我找不到解決這個問題的方法。TypeError:mousePos()只需要1個參數(給出2個)
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()
錯誤是告訴你'def mousePos(cord)'接受一個參數'cord',而你傳遞兩個'mousePos(311,397)'。 – meghamind