Seung gun Lee
Seung gun Lee

Reputation: 1

find my mouse position. help me

I have two questions about making mouse position.

I don't know why this code is not working. This code presents current mouse position, but the problem is print('\b' * len(positionStr), end='', flush=True). It is not working. The book said it removes the old position of the mouse, but it did not work.

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

Second, why doesn't it work in pycharm? I just can try that in the python idle.

Upvotes: 0

Views: 345

Answers (1)

nandal
nandal

Reputation: 2634

Try the following code with 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')

It works fine with python 2.7

Upvotes: 1

Related Questions