By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,353 Members | 1,237 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,353 IT Pros & Developers. It's quick & easy.

win32api.SetCursorPos() question

P: n/a
I'm trying to use win32api.SetCursorPos() to position the cursor in a
Tkinter canvas window. I.e.:

from Tkinter import *
import win32api
root = Tk()
canvas = Canvas(root, width=400, height=300, bg='white')
canvas.pack()
win32api.SetCursorPos(100,100)
root.mainloop()

But this code produces:

Traceback (most recent call last):
File
"C:\Python22\Lib\site-packages\Pythonwin\pywin\framework\scriptutils.py" ,
line 301, in RunScript
exec codeObject in __main__.__dict__
File "C:\My Documents\Python\Ascii\Script4.py", line 6, in ?
win32api.SetCursorPos(100,100)
TypeError: SetCursorPos() takes exactly 1 argument (2 given)

Am I using this function incorrectly? A search on Google didn't turn up much
but I did find one bit of code in which it was used in this manner.

I suspect there may be other problems with this approach so any further
comments will be appreciated also. I'm using ActivePython 2.2.2 build 224 on
Win98SE.

Thanks,
Gary Richardson


Jul 18 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Gary Richardson wrote:
I'm trying to use win32api.SetCursorPos() to position the cursor in a
Tkinter canvas window. I.e.:

from Tkinter import *
import win32api
root = Tk()
canvas = Canvas(root, width=400, height=300, bg='white')
canvas.pack()
win32api.SetCursorPos(100,100)
root.mainloop()

But this code produces:

Traceback (most recent call last):
File
"C:\Python22\Lib\site-packages\Pythonwin\pywin\framework\scriptutils.py" ,
line 301, in RunScript
exec codeObject in __main__.__dict__
File "C:\My Documents\Python\Ascii\Script4.py", line 6, in ?
win32api.SetCursorPos(100,100)
TypeError: SetCursorPos() takes exactly 1 argument (2 given)

Am I using this function incorrectly? A search on Google didn't turn up much
but I did find one bit of code in which it was used in this manner.

I suspect there may be other problems with this approach so any further
comments will be appreciated also. I'm using ActivePython 2.2.2 build 224 on
Win98SE.

Different then what the docs say, this function seems to want a tuple as
argument. See if win32api.SetCursorPos((100,100)) does the trick.

--
Vincent Wehren
Thanks,
Gary Richardson


Jul 18 '05 #2

P: n/a

"vincent wehren" <vi*****@visualtrans.de> wrote in message
news:ci**********@news5.zwoll1.ov.home.nl...
Gary Richardson wrote:
I'm trying to use win32api.SetCursorPos() to position the cursor in a
Tkinter canvas window. I.e.:

from Tkinter import *
import win32api
root = Tk()
canvas = Canvas(root, width=400, height=300, bg='white')
canvas.pack()
win32api.SetCursorPos(100,100)
root.mainloop()

But this code produces:

Traceback (most recent call last):
File
"C:\Python22\Lib\site-packages\Pythonwin\pywin\framework\scriptutils.py" , line 301, in RunScript
exec codeObject in __main__.__dict__
File "C:\My Documents\Python\Ascii\Script4.py", line 6, in ?
win32api.SetCursorPos(100,100)
TypeError: SetCursorPos() takes exactly 1 argument (2 given)

Am I using this function incorrectly? A search on Google didn't turn up much but I did find one bit of code in which it was used in this manner.

I suspect there may be other problems with this approach so any further
comments will be appreciated also. I'm using ActivePython 2.2.2 build 224 on Win98SE.


Different then what the docs say, this function seems to want a tuple as
argument. See if win32api.SetCursorPos((100,100)) does the trick.

--
Vincent Wehren


I tried that. It doesn't produce an error but no cursor appears.
Jul 18 '05 #3

P: n/a
Am Samstag, 18. September 2004 22:41 schrieb Gary Richardson:
I tried that. It doesn't produce an error but no cursor appears.


I don't know much about the win32-api, but SetCursorPos sounds like a
text-console command, not like something that has to do with windows.
Funtions that operate on a window take a HWND (window handle), but this
function doesn't, so this certainly sounds like text-console.

Now, why are you trying to position the cursor in a Tk Window anyway? The
Tk-Window is no text console, it's just a plain window on the screen, and you
can draw in the window using the normal Tk drawing primitives.

Maybe, if you post some more info on what you're trying to do, can we help you
better...

Heiko.
Jul 18 '05 #4

P: n/a

"Heiko Wundram" <he*****@ceosg.de> wrote in message
news:ma**************************************@pyth on.org...
Am Samstag, 18. September 2004 22:41 schrieb Gary Richardson:
I tried that. It doesn't produce an error but no cursor appears.
I don't know much about the win32-api, but SetCursorPos sounds like a
text-console command, not like something that has to do with windows.
Funtions that operate on a window take a HWND (window handle), but this
function doesn't, so this certainly sounds like text-console.

Now, why are you trying to position the cursor in a Tk Window anyway? The
Tk-Window is no text console, it's just a plain window on the screen, and

you can draw in the window using the normal Tk drawing primitives.

Maybe, if you post some more info on what you're trying to do, can we help you better...

Heiko.


Heiko,

Thank you for your reply. It encouraged me to read the MSVS documentation on
cursors a little more closely and to try a few things. I found that the
win32api function GetCursorPos() returns the position of the cursor with
respect to the computer screen so assuming that SetCursorPos() uses the same
coordinate system, I would have to add to my window coordinates the position
of the canvas with respect to the screen. I then took another look at
Vincent Wehren's and DogWalker's (direct email) suggestion that I pass
SetCursorPos() a tuple instead of a pair of values and found that did indeed
work. The cursor was there, it just wasn't where I expected it to be.

I'm using a Tk Canvas window to display various objects, one of which can be
a block of text entered from the keyboard. The user positions the cursor to
the desired position and begins typing, terminating the entry by pressing
the Esc key. From that point the text block can be manipulated (moved,
copied or deleted) by means of the mouse. As it is now, during text entry,
there is no indication of where the next character is to be entered. So I
thought it would be nice if I could indicate the insertion point as is usual
with text entry programs, editors, etc.

Thanks for all the help.

Gary

Jul 18 '05 #5

P: n/a
Gary Richardson wrote:
I'm using a Tk Canvas window to display various objects, one of which can be
a block of text entered from the keyboard. The user positions the cursor to
the desired position and begins typing, terminating the entry by pressing
the Esc key. From that point the text block can be manipulated (moved,
copied or deleted) by means of the mouse. As it is now, during text entry,
there is no indication of where the next character is to be entered. So I
thought it would be nice if I could indicate the insertion point as is usual
with text entry programs, editors, etc.


that's what the icursor method is there for. see:

http://effbot.org/zone/editing-canvas-text-items.htm

</F>

Jul 18 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.