【发布时间】:2019-05-24 03:28:19
【问题描述】:
我正在尝试编写一个程序,当我移动鼠标光标时,它会不断显示鼠标光标的 x 和 y 坐标(自动化 python 第 417 页中的无聊内容)。
我已经尝试调整 Try 语句的缩进,但我仍然 收到缩进错误信息。
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)
我希望输出如下两行:
按 Ctrl-C 退出。 X:290 Y:424
但我得到的输出是:
File "<ipython-input-2-b3f3ee266ed5>", line 6
except KeyboardInterrupt:
^
IndentationError: expected an indented block
【问题讨论】:
-
见上文。你的
while True:行后面必须跟循环体。
标签: python user-interface jupyter-notebook