pyautogui
(PythonAutoGUI)随笔
常用
pyautogui.position()
【功能】
- 获取鼠标所在处的坐标;
【实操】
代码01
import pyautoguiprint(type(pyautogui.position())) while True:print("\r" + str(pyautogui.position()), end=" ")
结果01
<class 'pyautogui.Point'> Point(x=1858, y=295) Process finished with exit code -1
说明01
- 获取鼠标坐标的方法其实有很多的,以后会集中记录一下;
pyautogui.click()
【功能】
- 实现鼠标点击操作;
pyautogui.Screenshot()
【功能】
- 截取屏幕画面信息;
【实操】
代码01
import pyautoguiprint(type(pyautogui.screenshot())) print(pyautogui.screenshot()) print(pyautogui.screenshot(r"C:\Users\SUNxRUN\Desktop\picture.png")) print(pyautogui.screenshot(region=(0, 0, 300, 400))) print(pyautogui.screenshot(r"C:\Users\SUNxRUN\Desktop\picture.png", region=(0, 0, 300, 400)))
结果01
<class 'PIL.Image.Image'> <PIL.Image.Image image mode=RGB size=1920x1080 at 0x23232B808D0> <PIL.Image.Image image mode=RGB size=1920x1080 at 0x23232B82E50> <PIL.Image.Image image mode=RGB size=300x400 at 0x23232D632D0> <PIL.Image.Image image mode=RGB size=300x400 at 0x23232D61590>Process finished with exit code 0
说明01
- 一股脑的先全部列出来,就不细说了;
pyautogui.locateOnScreen()
【功能】
- 获取某图片在屏幕中的坐标信息;
【实操】
代码01
import pyautoguipyautogui.screenshot(r"C:\Users\SUNxRUN\Desktop\picture.png", region=(0, 0, 300, 400))print(type(pyautogui.locateOnScreen(r"C:\Users\SUNxRUN\Desktop\picture.png"))) print(pyautogui.locateOnScreen(r"C:\Users\SUNxRUN\Desktop\picture.png"))
结果01
<class 'pyscreeze.Box'> Box(left=0, top=0, width=300, height=400)Process finished with exit code 0
说明01
- 就先不展开细说了;
pyautogui.locateCenterOnScreen()
【功能】
- 获取某图片在屏幕中的中心坐标;
【实操】
代码01
import pyautoguipyautogui.screenshot(r"C:\Users\SUNxRUN\Desktop\picture.png", region=(0, 0, 300, 400))print(type(pyautogui.locateCenterOnScreen(r"C:\Users\SUNxRUN\Desktop\picture.png"))) print(pyautogui.locateCenterOnScreen(r"C:\Users\SUNxRUN\Desktop\picture.png"))
结果01
<class 'pyscreeze.Point'> Point(x=150, y=200)Process finished with exit code 0
说明01
- 暂不展开细说;
附带
\r
【功能】
- 将光标回退到开始位置;
【实操】
代码01
for i in range(3):print("点个关注不迷路!!!谢谢......")
结果01
点个关注不迷路!!!谢谢...... 点个关注不迷路!!!谢谢...... 点个关注不迷路!!!谢谢......Process finished with exit code 0
说明01
- 普通式起手,对比各段代码即可理解,另外探索了下"
end=
"的用法;代码02
for i in range(3):print("\r点个关注不迷路!!!谢谢......")
结果02
点个关注不迷路!!!谢谢...... 点个关注不迷路!!!谢谢...... 点个关注不迷路!!!谢谢......Process finished with exit code 0
说明02
- 加"
\r
"后并没有像想象中的那样,故做了很多段的代码尝试;代码03
for i in range(3):print("\r点个关注不迷路!!!谢谢......", end="")
结果03
点个关注不迷路!!!谢谢...... Process finished with exit code 0
说明03
- 此段代码片段达到了我的预期效果,但有些不太理解"
end=
";代码04
for i in range(3):print("点个关注不迷路!!!谢谢......", end="")
结果04
点个关注不迷路!!!谢谢......点个关注不迷路!!!谢谢......点个关注不迷路!!!谢谢...... Process finished with exit code 0
说明04
- 此段代码纯纯是想看"
\r
"和end=
"的功能是什么,分开运行看结果;代码05
for i in range(3):print("点个关注不迷路!!!谢谢......", end="(好像很奇怪的样子) ")
结果05
点个关注不迷路!!!谢谢......(好像很奇怪的样子) 点个关注不迷路!!!谢谢......(好像很奇怪的样子) 点个关注不迷路!!!谢谢......(好像很奇怪的样子) Process finished with exit code 0
说明06
- 我理解了,哈哈,一团浆糊,"
\r\n
"的理解现在想起来了,结束;