-1

I am making this small program, where the user can input the x and y axis of the screen where they wish to move the mouse to, and how many time they would like to click on that pixel.

My problem is when I try to put the variables into this function, the arguments apparently cannot be converted? The SetCurPos() is the problem, it will take SetCurPos(x,y), but I receive the error:


    File "C:\Python27\Scripts\ManipulationTools.py", line 13, in click
        SetCursorPos(x,y)
    ArgumentError: argument 1: : Don't know how to convert parameter 1

My Code:


    from Tkinter import *
    import time
    import ctypes
    #from MoveCursor import click

    class ManipulationTools():

    ##############FUNCTIONS###################################
        def click(x,y, numclicks):
            SetCursorPos = ctypes.windll.user32.SetCursorPos
            mouse_event = ctypes.windll.user32.mouse_event

            SetCursorPos(x,y)
            E1.DELETE(0, END)
            E2.DELETE(0, END)
            E3.DELETE(0, END)

            for i in xrange(numclicks):
                mouse_event(2,0,0,0,0)
                mouse_event(4,0,0,0,0)



    #############END FUNCTIONS################################   
        root = Tk()

        root.maxsize(width=400, height=400)
        root.minsize(width=400, height=400)

        root.config(bg="black")

        L1 = Label(root,text="Enter the x and y value here:", fg="white", bg="black")
        L1.place(x=20, y=20)
        Lx = Label(root, text="X:",fg="white",bg="black")
        Lx.place(x=170,y=20)
        Ly = Label(root, text="Y:",fg="white",bg="black")
        Ly.place(x=240,y=20)
        Lnum = Label(root, text="Number of Times:",fg="white",bg="black")
        Lnum.place(x=150, y=100)

        E1 = Entry(root, width=5, bg="grey", )
        E1.place(x=190,y=20)
        E2 = Entry(root, width=5, bg="grey",)
        E2.place(x=260,y=20)
        E3 = Entry(root, width=5, bg="grey",)
        E3.place(x=260,y=100)

        a=IntVar(E1.get())
        b=IntVar(E2.get())
        c=IntVar(E3.get())


        con = Button(root, command=click(a,b,c), text="Confirm", bg="white")
        con.place(x=300,y=300)

        root.mainloop()

My Traceback error when I click the button to confirm the numbers in the fields entered:


    Traceback (most recent call last):
      File "C:\Python27\Scripts\ManipulationTools.py", line 6, in 
        class ManipulationTools():
      File "C:\Python27\Scripts\ManipulationTools.py", line 53, in ManipulationTools
        con = Button(root, command=click(a,b,c), text="Confirm", bg="white")
      File "C:\Python27\Scripts\ManipulationTools.py", line 13, in click
        SetCursorPos(x,y)
    ArgumentError: argument 1: : Don't know how to convert parameter 1

Conor Thompson
  • 198
  • 1
  • 15

1 Answers1

1

What you call ####functions#### are actually methods, and hence, the first argument they get is always the reference to the instance of their containing class, which commonly is named self. You can, however, name that parameter like you want to, which is what happened here:

class ManipulationTools():
    def click(x,y, numclicks):

x is what elsewhere would be called self, not the first argument that you give when doing something like

tools = ManipulationTools()
tools.click(100,200,1) ## this should actually give you an error -- ManipulationTools.click gets called with 4 arguments (self, 100, 200, 1), but is only defined for 3 (self, y, numclicks)

The right thing to do is:

class ManipulationTools():
    def click(self, x,y, numclicks):
Marcus Müller
  • 34,677
  • 4
  • 53
  • 94