關(guān)于Python的pymouse click 雙擊的問(wèn)題
Python pymouse click 雙擊
m.click是雙擊
想讓點(diǎn)擊一次
最后就用下面任意一個(gè)。。。
按下:m.press(x,y)
松開(kāi):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語(yǔ)法
函數(shù)通過(guò)裝飾來(lái)成為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è)問(wèn)題的答案是Click嘗試以相同的方式支持Python 2和Python 3
從Click 2.0開(kāi)始,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)建命令。上面的腳本可以這樣編寫(xiě):
@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)文章
用?Python?繪制全國(guó)鴻星爾克門(mén)店分布圖
這篇文章主要介紹了用?Python?繪制全國(guó)鴻星爾克門(mén)店分布圖,今天就以某度地圖?用Python爬蟲(chóng)看一下全國(guó)到底有多少家鴻星爾克門(mén)店,,需要的朋友可以參考一下2022-01-01
使用Python實(shí)現(xiàn)Office文檔(Word/Excel/PowerPoint)批量轉(zhuǎn)換為PDF
在處理不同格式的Office文檔(如Word、Excel和PowerPoint)時(shí),將其轉(zhuǎn)換為PDF格式是常見(jiàn)的需求,本文就跟隨小編來(lái)看看如何使用Python將Word/Excel/PowerPoint批量轉(zhuǎn)換為PDF吧2024-10-10
Python多進(jìn)程multiprocessing.Pool類詳解
這篇文章主要為大家詳細(xì)介紹了Python多進(jìn)程multiprocessing.Pool類,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-04-04
使用Pycharm創(chuàng)建一個(gè)Django項(xiàng)目的超詳細(xì)圖文教程
Django是比較經(jīng)典的Python web框架,最近剛好在項(xiàng)目中用到了Django,所以下面這篇文章主要給大家介紹了關(guān)于使用Pycharm創(chuàng)建一個(gè)Django項(xiàng)目的超詳細(xì)圖文教程,文中介紹的非常詳細(xì),需要的朋友可以參考下2022-08-08
Python實(shí)現(xiàn)定期檢查源目錄與備份目錄的差異并進(jìn)行備份功能示例
這篇文章主要介紹了Python實(shí)現(xiàn)定期檢查源目錄與備份目錄的差異并進(jìn)行備份功能,涉及Python基于filecmp模塊的文件比較及讀寫(xiě)等相關(guān)操作技巧,需要的朋友可以參考下2019-02-02
Python實(shí)現(xiàn)貪吃蛇小游戲(雙人模式)
這篇文章主要為大家詳細(xì)介紹了Python實(shí)現(xiàn)雙人模式的貪吃蛇小游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-09-09

