I'm trying to write a program that will constantly display x- and y- coordinates of the mouse cursor as I move it around(Automate the boring stuff in python page 417).
I have tried adjusting indentation of the Try statements,but I was still receiving indentation error message.
import pyautogui
print('press Ctrl-C to quit.')
try:
while True:
except KeyboardInterrupt:
print('\nDone.')
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)
I expected an output of two lines like below:
press Ctrl-C to quit. X:290 Y:424
But the output I got was :
File "<ipython-input-2-b3f3ee266ed5>", line 6
except KeyboardInterrupt:
^
IndentationError: expected an indented block