亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用python截取特定空間的屏幕截圖

使用python截取特定空間的屏幕截圖

鳳凰求蠱 2023-07-05 10:21:14
我正在嘗試使用 python 截取特定區域的屏幕截圖。我寫了這段代碼:import pyscreenshotfrom pynput.mouse import Listenerx=1y=1def on_click(x1, y1, button, pressed):    global x,y    x = x1    y = y1def on_release(x2,y2, button, pressed):    global x,y    im = pyscreenshot.grab(x,y,x2,y2)    im.save("hello.png")#Collect events until releasedwith Listener(        on_click=on_click,        on_release=on_release) as listener:    listener.join()這里的問題是它不輸出任何內容。請幫助
查看完整描述

1 回答

?
偶然的你

TA貢獻1841條經驗 獲得超3個贊

我給你寫了一個代碼。在我這邊效果很好。請在運行我的代碼后讓我知道您的意見。


import pyscreenshot

from pynput.mouse import Listener, Button


global x0, y0



def on_click(x1, y1, button, pressed):

    global x0, y0


    if button == Button.left and pressed:

        x0, y0 = x1, y1


    if button == Button.left and not pressed:

        try:

            im = pyscreenshot.grab(bbox=(x0, y0, x1, y1))

            im.save("hello.png")

            print('Screenshot was taken.')

            return False

        except:

            pass


    return True


# Collect events until released

with Listener(

        on_click=on_click) as listener:

    try:

        listener.join()

    except:

        pass


查看完整回答
反對 回復 2023-07-05
  • 1 回答
  • 0 關注
  • 177 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號