gpt4 book ai didi

python - 如何获取 pygame 中鼠标点击位置的 RGB 值以及如何更改颜色? (Python 3.3.2)

转载 作者:太空宇宙 更新时间:2023-11-03 18:37:47 25 4
gpt4 key购买 nike

所以我正在使用 pygame 来制作一个绘画程序。我已经加载了我应该点击鼠标的色谱。除此之外,我不太确定如何使用 .get_at 来查找颜色,也不太确定如何更改颜色。

到目前为止我的代码是:

color = []
color = ((0,0,0))
running = True
while running:
mb = mouse.get_pressed()
mx,my = mouse.get_pos()
if mb[0] == 1 and palette.collidepoint(mx,my):
color = screen.get_at((mx,my))
color.append()

每次我点击我的调色板,我的颜色

最佳答案

import pygame, sys
pygame.init()
screen = pygame.display.set_mode([640,480])
mousepressed = False
color = (0,0,0,255)
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
mousepressed = True
if event.type == pygame.MOUSEBUTTONUP:
mousepressed = False
if mousepressed:
screen.set_at(pygame.mouse.get_pos(),color)
pygame.display.flip()

不好意思,有点着急,希望对你有帮助!

关于python - 如何获取 pygame 中鼠标点击位置的 RGB 值以及如何更改颜色? (Python 3.3.2),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21212737/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com