日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

Py之PyAutoGUI:python库之PyAutoGUI的简介、安装、使用方法

發(fā)布時間:2025/3/21 python 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Py之PyAutoGUI:python库之PyAutoGUI的简介、安装、使用方法 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Py之PyAutoGUI:python庫之PyAutoGUI的簡介、安裝、使用方法

?

目錄

PyAutoGUI的簡介

PyAutoGUI的安裝

PyAutoGUI的使用方法


?

?

?

PyAutoGUI的簡介

? ? PyAutoGUI是一個純Python的GUI自動化工具,其目的是可以用程序自動控制鼠標(biāo)和鍵盤操作,利用它可以實現(xiàn)自動化任務(wù)。讓所有GUI都自動化? 本教程譯自大神Al Sweigart的PyAutoGUI項目,Python自動化工具,更適合處理GUI任務(wù),網(wǎng)頁任務(wù)推薦。PyAutoGUI可以模擬鼠標(biāo)的移動、點擊、拖拽,鍵盤按鍵輸入、按住操作,以及鼠標(biāo)+鍵盤的熱鍵同時按住等操作,可以說手能動的都可以。

? ? ?The purpose of PyAutoGUI is to provide a cross-platform Python module for GUI automation?for human beings. The API is designed to be as simple as possible with sensible defaults.

?

參考文獻(xiàn)
Welcome to PyAutoGUI’s documentation
Doc PyAutoGUI

?

PyAutoGUI的安裝

pip install pyautogui

哈哈,大功告成!

?

PyAutoGUI的使用方法

#關(guān)于庫下函數(shù)使用方法概況<br>import pyautogui#關(guān)于屏幕分辨率、鼠標(biāo)坐標(biāo)等 position=pyautogui.position() resolution=pyautogui.size() if_position=pyautogui.onScreen(1900, 2000) print(position,resolution,if_position)#1.1、關(guān)于鼠標(biāo)光標(biāo)定位 pyautogui.moveTo(screenWidth / 2, screenHeight / 2) pyautogui.moveTo(100,100) pyautogui.moveTo(x=10, y=10, duration=3) #緩動/漸變、Tween/Easing函數(shù):這些效果函數(shù)是模仿Al Sweigart的PyTweening模塊,可以直接使用,不需要額外安裝。 pyautogui.moveTo(100, 100, 2, pyautogui.easeInQuad) pyautogui.moveTo(100, 100, 2, pyautogui.easeOutQuad) pyautogui.moveTo(100, 100, 2, pyautogui.easeInOutQuad) pyautogui.moveTo(100, 100, 2, pyautogui.easeInBounce) pyautogui.moveTo(100, 100, 2, pyautogui.easeInElastic)pyautogui.moveRel(None, 10) pyautogui.moveRel(xOffset=1000, yOffset=1000, duration=6)#1.2、關(guān)于鼠標(biāo)按下松開 pyautogui.mouseDown(button='right'); pyautogui.mouseUp(button='right') pyautogui.mouseDown(button='right') pyautogui.mouseUp(button='right', x=100, y=200) #1.3、關(guān)于鼠標(biāo)點擊 #為了操作方便,PyAutoGUI提供了doubleClick()、tripleClick()、rightClick()來實現(xiàn)雙擊、三擊、右擊操作 #pyautogui.click(x=moveToX, y=moveToY, clicks=num_of_clicks, interval=secs_between_clicks, button='left') pyautogui.click(x=100, y=200, duration=2) pyautogui.click(button='right', clicks=2, interval=0.25) pyautogui.dragTo(300, 400, 2, button='left') #1.4、關(guān)于鼠標(biāo)滾動 # pyautogui.scroll(clicks=amount_to_scroll, x=moveToX, y=moveToY) pyautogui.scroll(10) pyautogui.scroll(10, x=100, y=100) #2.1、關(guān)于鍵盤按下松開 key_name=pyautogui.KEYBOARD_KEYS[:10] pyautogui.keyDown(key_name) pyautogui.keyUp(key_name)#2.2typewrite()普通鍵:鍵盤上可以按的鍵都可以調(diào)用,typewrite()函數(shù)只能用于單個字符鍵,不能按SHITF和F1這些功能鍵。 pyautogui.typewrite('Hello world!\n', interval=0.1) pyautogui.typewrite(['a', 'b', 'c', 'left', 'backspace', 'enter', 'f1'], interval=secs_between_keys)#2.3press()功能鍵:press()函數(shù)其實是keyDown()和keyUp()函數(shù)的包裝,模擬的按下然后松開兩個動作。 pyautogui.press('esc') pyautogui.press('enter') pyautogui.press('f1') pyautogui.press('left') pyautogui.keyUp('shift')#2.4熱鍵組合;('ctrl', 'a')全選、('ctrl', 'c')復(fù)制、('ctrl', 'v')粘貼 pyautogui.hotkey('ctrl', 'a')#3、關(guān)于消息彈窗函數(shù): pyautogui.alert('這個消息彈窗是文字+OK按鈕') pyautogui.confirm('這個消息彈窗是文字+OK+Cancel按鈕') pyautogui.prompt('這個消息彈窗是讓用戶輸入消息的,單擊OK')#4、關(guān)于截屏的函數(shù):屏幕位置使用X和Y軸的笛卡爾坐標(biāo)系。原點(0,0)在左上角,分別向右、向下增大。 如果屏幕像素是 1920×10801920×1080 ,那么右下角的坐標(biāo)是(1919, 1079)。 pyautogui.screenshot('C:/Users/99386/Desktop/screenshot.png') position_four=pyautogui.locateOnScreen('C:/Users/99386/Desktop/screenshot.png') for i in pyautogui.locateAllOnScreen('C:/Users/99386/Desktop/screenshot.png'):print(i) list1=list(pyautogui.locateAllOnScreen('C:/Users/99386/Desktop/screenshot.png')) position_center=pyautogui.locateCenterOnScreen('C:/Users/99386/Desktop/screenshot.png') print(position_four,list1,position_center)

相關(guān)文章
Py之PyAutoGUI:python的PyAutoGUI庫(讓所有GUI都自動化)使用方法總結(jié)

?

總結(jié)

以上是生活随笔為你收集整理的Py之PyAutoGUI:python库之PyAutoGUI的简介、安装、使用方法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。