I've realized that it would be very helpful to me to SET the mouse cursor to a particular location. Having done the usual internet searches, I can't seem to find anything on how to do it. Any ideas?

(So I'm still set on converting to wx, but the project I've just done in Tkinter needs to get finished ASAP. It's an experiment and we need to start running participants.)

Hmm, I don't think I want either of those things. I want to be able to tell the program to move the mouse cursor to position x, y.

use mouseover or mousefocus at X,Y

use mouseover or mousefocus at X,Y

We are talking about the Tkinter GUI toolkit. There are no such methods.

widget.focus() puts the cursor to a widget

module turtle (uses tkinter) has a method goto(x,y)

Aot,

Did you find a solution?

regards

Nope, never found a solution in Tkinter.

I can't think of any practical use for this.

I can't think of any practical use for this.

I'm a cognitive scientist; I use python to code experiments which often present stimuli to participants that they respond to. If I am timing their responses, sometimes I want very precise control over where the mouse cursor is.

In this particular case, I was making an experiment where participants would see two stimuli, one after another (say a circle and then a bigger circle), and then they would have to rate each on a vertical scale of radio buttons. Because I was timing them, I wanted the mouse cursor to always start in the middle of the scale, so I could time how long it took them to move the cursor from the middle to whichever button they chose.

Originally I just wanted the cursor to disappear during the stimuli presentation, but I couldn't find a way to do that, so I thought perhaps I could simply set the cursor to the center at the start of the radio-button rating.

In the end I just had to ask them not to move their cursor at all while the stimuli were on screen and coded it so that the screen would flash red at them if they did.

So, yeah. It has its uses. :-P

You did not specify what OS you're coding in, but this one is to get the mouse position in Linux, and apparently in the same thread, Gribouillis gives an answer on how to do it in Windows as well. Also read vagaseat's post, which is interesting. Hope this helps.

Thanks! Although I've long since solved the problem for my particular study and hope to do future studies using wx. It still might come in handy.

You did not specify what OS you're coding in, but this one is to get the mouse position in Linux, and apparently in the same thread, Gribouillis gives an answer on how to do it in Windows as well. Also read vagaseat's post, which is interesting. Hope this helps.

I think the problem is not how to get the mouse position, but how to set the mouse position.

Ah yes. I'm sorry, it is about SETTING the mouse position. I read that last post too quickly I see.

from ctypes import *
user = windll.user32
x = 640
y= 480
user.SetCursorPos(x,y)

Thanks! Even if it requires Windows, I appreciate a solution.

from ctypes import *
user = windll.user32
x = 640
y= 480
user.SetCursorPos(x,y)

Tech B,

Is there a way to this in linux?

Regards

I'm not running Linux nor have I worked with it besides network cracking via BackTrack.

But I've been told that xorg's xlib could help you out. You'll have to go through its doc's or hit google, but I believe it has the capability's your looking for.

Let me know how it goes.

Tech B,

Is there a way to this in linux?

Regards

Did you find what you where looking for?

Tech B,

Is there a way to this in linux?

Regards

You should experiment with the method warp_pointer in the python-xlib module. (See also XWarpPointer in the xlib documentation). The problem is to find the good arguments to warp_pointer...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.