繁体   English   中英

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

[英]How do I get the RGB value for where my mouse clicks in pygame and how do I change the colour? (Python 3.3.2)

因此,我正在使用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()

抱歉,急于求助!

mouseState = mouse.get_pressed()

mx, my = mouse.get_pos()
if mouseState[0]:
    color = screen.get_at((mx, my))
    # color is a Color object
    # Do some color manipulation by using Color.r, Color.g, Color.b, and Color.a
    # For example Color.r = 25
    # And at last...
    screen.set_at((mx, my), color)

那是你想要的吗? 阅读文档以查看Color.r等的值是多少。

http://www.pygame.org/docs/ref/color.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM