我正在嘗試做一個函數,它不斷打印出鼠標位置,直到停止。 進口pyautogui嘗試打印出鼠標位置時錯誤的輸出
import pyautogui
print('Press CTRL + "c" to stop')
while True:
try:
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('\nDone')
break
預期的輸出應該是這個樣子:
X:265 Y:634 只有一條線不斷刷新
但是,這是我什麼取而代之:
XXXXXXXXXXXXXXXXXXX:665 Y:587
XXXXXXXXXXXXXXXXX:665 Y:587
XXXXXXXXXXXXXXXXXXXX:665 Y:587
XXXXXXXXXX:718 Y:598
XXXXXXXXXXXX:1268 Y:766
除去\ B個字符 import pyautogui
print('Press CTRL + "c" to stop')
while True:
try:
x, y = pyautogui.position()
positionStr = 'X: ' + str(x).rjust(4) + ' Y: ' + str(y).rjust(4)
print(positionStr)
print('\b' * len(positionStr), end = '', flush = True)
except KeyboardInterrupt:
print('\nDone')
break
X:830 Y:543
X:830 Y:543
X:830 Y:543
X:830 Y:543
完成
的輸出是什麼,如果你做不打印'\ b'字符? –
更新了匹配的結果。它擺脫了重複的'x',但仍然不是潮紅 – MoRe
你是什麼意思,它不是潮? –