473,508 Members | 2,380 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

win32api.SetCursorPos() question

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
5 7370
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

"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
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

"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
48175
by: Matt Smith | last post by:
hi all, again.... having another problem with python COMs, I run a python script on a win2000 machine, that uses win32com.client and it runs perfectly, whereas when I come to run it on a win98...
2
4095
by: Josh | last post by:
Hi All, I am trying to print a pdf file from python using the Win32api shellexecute method and am having a problem, or perhaps just a misunderstanding, with the bshow parameter. Am I correct to...
2
1928
by: Nurchi BECHED | last post by:
Hello, my dearest respected brother, All! How do you make calls to Win32Api functions from C# I have an old example in Visual FoxPro... Kind of need to do the same in C# now... I need to get...
2
2788
by: Jim | last post by:
I am trying to figure out how to embed Python in a little C++ Windows console app. Here's the code: // Py_Initialize(); Py_InitializeEx(0); PyRun_SimpleString("from win32com.client import *");...
0
3799
by: Mike | last post by:
Hi. I have Python 2.4 installed on my local machine in c:\Python24. I have also downloaded the python for windows extensions installer pywin32-208.win32-py2.4.exe and installed this to...
5
2943
by: __schronos__ | last post by:
Hi all. Recently I've to developed a project in python that made operation under win32 platform and I found a lot of problema to find good information. The only one documentation is in...
1
6192
by: reginpc | last post by:
Hi, Please anyone say how to find win32api.py file and where its present?? i am Getting the below error... from win32com.shell import shell File...
1
1899
by: tkpmep | last post by:
I'm running Python 2.5.2 on Windows XP and need to interface with R, so I downloaded the R 2.6.2 statistical package and installed it, and did the same for RPy 1.02 (i made sure I got the version...
1
2812
by: Michiel Overtoom | last post by:
On Saturday 19 July 2008 21:13:04 Lamonte Harris wrote: What are the actions you do and the commands you give, and what is the precise error you get? Greetings, -- "The ability of the...
0
7115
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7321
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7377
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7036
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5624
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
414
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.