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

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

“pygame.Surface”對象的描述符“get_at”不適用于“元組”對象

“pygame.Surface”對象的描述符“get_at”不適用于“元組”對象

12345678_0001 2023-03-16 17:16:03
我正在創建一個程序,如果光標位置的像素還不是黑色,我會嘗試在光標位置繪制一個矩形。if pygame.Surface.get_at(pygame.mouse.get_pos()) != (0,0,0,255):    pygame.draw.rect(win, (0,0,0), (x, y, 3, 3))當我嘗試實現 pygame.Surface.get_at() 時發生錯誤,它說...TypeError: descriptor 'get_at' for 'pygame.Surface' objects doesn't apply to a 'tuple' object.. 即使 pygame.Surface.get_at() 在https://pygame.org上的文檔顯示該方法的輸入應該是一個元組。get_at()    get the color value at a single pixel    get_at((x, y)) -> Color    Return a copy of the RGBA Color value at the given pixel. If the Surface has no per pixel alpha, then     the alpha value will always be 255 (opaque). If the pixel position is outside the area of the Surface     an IndexError exception will be raised.我怎樣才能解決這個問題?
查看完整描述

1 回答

?
一只甜甜圈

TA貢獻1836條經驗 獲得超5個贊

您需要調用get_atpygame.Surface 對象,而不是類本身。



screen = pygame.display.set_mode(size)


pixel = screen.get_at(pygame.mouse.get_pos()) #gets the pixel on the screen surface


another_surface = pygame.Surface((100, 100))


another_pixel = another_surface.get_at((50, 50)) #gets the pixel from the 'another_surface' surface




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

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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