472,800 Members | 1,375 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,800 software developers and data experts.

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 7175
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
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
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
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
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
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
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
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
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
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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.