關(guān)于Python的pymouse click 雙擊的問題
Python pymouse click 雙擊
m.click是雙擊
想讓點(diǎn)擊一次
最后就用下面任意一個(gè)。。。
按下:m.press(x,y)
松開:m.release(x,y)
Python學(xué)習(xí)筆記|python之click
1.什么是click
2.如何安裝
使用命令pip install click或者在PyCharm中安裝
3.隔離環(huán)境vitualenv
linux或MAC上
sudo pip install virtualenv
windows
pip install virtualenv
4.如何激活
現(xiàn)在,每當(dāng)您想要處理項(xiàng)目時(shí),您只需激活相應(yīng)的環(huán)境。在OS X和Linux上,執(zhí)行以下操作:
$ . venv/bin/activate
如果您是Windows用戶,則以下命令適合您:
$ venv\scripts\activate
退出激活
$ deactivate
輸入以下命令以在virtualenv中激活Click:
$ pip install Click
5.click語法
函數(shù)通過裝飾來成為Click命令行工具 click.command()。最簡(jiǎn)單的方法是,使用這個(gè)裝飾器裝飾一個(gè)函數(shù)會(huì)使它成為一個(gè)可調(diào)用的腳本:
import click @click.command() @click.option('--count', default=1, help='Number of greetings.') @click.option('--name', prompt='Your name', help='The person to greet.') def hello(count, name): """Simple program that greets NAME for a total of COUNT times.""" for x in range(count): click.echo('Hello %s!' % name) if __name__ == '__main__': hello()
根據(jù)參數(shù)格式執(zhí)行
$ python hello.py --count=3 Your name: John Hello John! Hello John! Hello John!
自動(dòng)生成幫助文檔
$ python hello.py --help Usage: hello.py [OPTIONS] Simple program that greets NAME for a total of COUNT times. Options: --count INTEGER Number of greetings. --name TEXT The person to greet. --help Show this message and exit.
6.打印函數(shù)click.echo
使用echo()而不是常規(guī) print()函數(shù)?這個(gè)問題的答案是Click嘗試以相同的方式支持Python 2和Python 3
從Click 2.0開始,echo函數(shù)也對(duì)ANSI顏色有很好的支持
7.嵌套命令
使用@click.group()實(shí)現(xiàn)命令的嵌套,即可以存在子命令
@click.group() def cli(): pass @click.command() def initdb(): click.echo('Initialized the database') @click.command() def dropdb(): click.echo('Dropped the database') cli.add_command(initdb) cli.add_command(dropdb)
正如您所看到的,group()裝飾器的工作方式與command() 裝飾器類似,但創(chuàng)建了一個(gè)Group對(duì)象,可以為其提供多個(gè)可以附加的子命令Group.add_command()。
對(duì)于簡(jiǎn)單腳本,也可以使用Group.command()裝飾器自動(dòng)附加和創(chuàng)建命令。上面的腳本可以這樣編寫:
@click.group() def cli(): pass @cli.command() def initdb(): click.echo('Initialized the database') @cli.command() def dropdb(): click.echo('Dropped the database')
然后,您將Group在setuptools入口點(diǎn)或其他調(diào)用中調(diào)用:
if __name__ == '__main__': cli()
8.增加參數(shù)
添加參數(shù)@click.option要添加參數(shù),請(qǐng)使用option()和argument()裝飾器:
@click.command() @click.option('--count', default=1, help='number of greetings') @click.argument('name') def hello(count, name): for x in range(count): click.echo('Hello %s!' % name)
生成的幫助文檔如下
$ python hello.py --help Usage: hello.py [OPTIONS] NAME Options: --count INTEGER number of greetings --help Show this message and exit.
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
PyTorch實(shí)現(xiàn)更新部分網(wǎng)絡(luò),其他不更新
今天小編就為大家分享一篇PyTorch實(shí)現(xiàn)更新部分網(wǎng)絡(luò),其他不更新,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-12-12python利用wx實(shí)現(xiàn)界面按鈕和按鈕監(jiān)聽和字體改變的方法
今天小編就為大家分享一篇python利用wx實(shí)現(xiàn)界面按鈕和按鈕監(jiān)聽和字體改變的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-07-07Opencv實(shí)現(xiàn)計(jì)算兩條直線或線段角度方法詳解
這篇文章主要介紹了Opencv實(shí)現(xiàn)計(jì)算兩條直線或線段角度方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧2022-12-12pyqt實(shí)現(xiàn).ui文件批量轉(zhuǎn)換為對(duì)應(yīng).py文件腳本
今天小編就為大家分享一篇pyqt實(shí)現(xiàn).ui文件批量轉(zhuǎn)換為對(duì)應(yīng).py文件腳本,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-06-06pandas調(diào)整列的順序以及添加列的實(shí)現(xiàn)
這篇文章主要介紹了pandas調(diào)整列的順序以及添加列的實(shí)現(xiàn)操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2021-03-03Python采集圖片數(shù)據(jù)的實(shí)現(xiàn)示例
本文主要介紹了Python采集圖片數(shù)據(jù)的實(shí)現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-04-04解決Pytorch訓(xùn)練過程中l(wèi)oss不下降的問題
今天小編就為大家分享一篇解決Pytorch訓(xùn)練過程中l(wèi)oss不下降的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-01-01Python使用Joblib模塊實(shí)現(xiàn)加快任務(wù)處理速度
在Python編程中,處理大規(guī)模數(shù)據(jù)或者進(jìn)行復(fù)雜的計(jì)算任務(wù)時(shí),通常需要考慮如何提高程序的運(yùn)行效率,本文主要介紹了如何使用Joblib模塊來加快任務(wù)處理速度,需要的可以參考下2024-03-03