【问题标题】:find my mouse position. help me找到我的鼠标位置。帮我
【发布时间】:2018-06-04 12:11:39
【问题描述】:

我有两个关于鼠标定位的问题。

我不知道为什么这段代码不起作用。此代码显示当前鼠标位置,但问题是print('\b' * len(positionStr), end='', flush=True)。它不工作。书上说去掉了鼠标的旧位置,但是没用。

import pyautogui
print('Press Ctrl-C to quit')
try:
    while True:
        x, y = pyautogui.position()
        positionStr = 'X: ' + str(x).rjust(4) + ' Y: ' + str(y).rjust(4)
        print(positionStr, end='')
        print('\b' * len(positionStr), end='', flush=True)
except KeyboardInterrupt:
    print('\n')

Screenshot

第二,为什么在pycharm中不起作用?我可以在 python idle 中尝试一下。

【问题讨论】:

标签: python mouse


【解决方案1】:

用python2试试下面的代码:-

import pyautogui
print('Press Ctrl-C to quit')
try:
    while True:
        x, y = pyautogui.position()
        positionStr = 'X: ' + str(x).rjust(4) + ' Y: ' + str(y).rjust(4)
        print(positionStr)
        print('\b' * len(positionStr))
except KeyboardInterrupt:
    print('\n')

它适用于 python 2.7

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-30
    • 1970-01-01
    • 2018-01-23
    • 1970-01-01
    • 2017-02-22
    相关资源
    最近更新 更多