英文:
How to make the mouse cursor's position only update in the monitor when the python program says so?
问题
在Python的turtle中,如果程序使用"Screen.tracer(0)",那么只有在"Screen.update()"被调用之后,对屏幕的任何更改才会显示出来。我想知道是否有一种方法可以使用鼠标光标来实现这个效果,使其可以自由移动,但在程序调用之前,它会保持在原位。
我没有找到任何解决方案。我尝试了使用"pyautogui.moveTo()"不断将鼠标保持在一个位置,但当我移动鼠标足够快时,光标会离开该位置,然后又回到原来的位置,但我希望它完全停留在那里。
英文:
In python turtle, if the program says "Screen.tracer(0)", then any changes can be made in the screen and they will only appear once "Screen.update()" is said. I'd like to know if there is a way to make it possible with the mouse cursor so that it can be moved as much as wanted, but until the program says so, it would remain in the same position.
I didn't find any solutions to this. I tried to keep the mouse in one position by repeatadly using "pyautogui.moveTo()", but when I was moving the mouse fast enough, the cursor left that position and then did move back, but I'd like it to stay there completely.
答案1
得分: 0
使用 pynput
。 (pip install pynput
)
import pynput
使鼠标冻结:
mouse_listener = pynput.mouse.Listener(suppress=True)
mouse_listener.start()
要取消冻结: mouse_listener.stop()
注意:如果第一次没有正确实施,冻结鼠标可能会导致你陷入困境。不过,你应该能够使用 Alt + F4
来结束进程。
希望这有所帮助!
英文:
Use pynput
. (pip install pynput
)
import pynput
To have the mouse freeze:
mouse_listener = pynput.mouse.Listener(suppress=True)
mouse_listener.start()
To unfreeze it: mouse_listener.stop()
Note: freezing the mouse can get you stuck in a few ways if you don't implement it properly the first time. You should be able to Alt + F4
to end the process, though.
Hope this helps!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论