python - 如何在 python 中使用十六进制值而不是 RGB 值。蟒蛇 2.7
问题描述
我不喜欢 RGB,我用 HEX 代替。我是 Python 新手,这就是我的代码的样子;我如何使用十六进制。对不起我不是来自美国的英语。
import pygame
black = (0,0,0)
white = (255,255,255)
blue = ("#7ec0ee")
pygame.init()
size = 1024,768
screen = pygame.display.set_mode(size)
pygame.display.set_caption("Code for Stack")
done = False
clock = pygame.time.Clock()
while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
screen.fill(blue)
pygame.display.flip()
clock.tick(60)
pygame.quit()
解决方案
pygame.Color
支持十六进制参数。所以你可以这样做:
blue = pygame.Color("#7ec0ee")
screen.fill(blue)
这会自动将您的颜色转换为 RGBA 值。所以如果你去打印颜色,你会看到:
(126, 192, 238, 255)
推荐阅读
- c# - C#在一行中获取多行
- c# - JQuery 数据表在我的 Blazor 和 .NET 核心项目中不起作用
- excel - 有没有办法比较单元格值,然后根据值对单元格进行着色
- javascript - 如何在 html 中显示数据库中的两个数据值?
- arrays - 基于两个现有字典创建新字典
- react-native - 使用 rn-diff-purge 将 react-native 从 0.50.4 升级到 0.60.0
- r - 有效地重塑大数据集
- javascript - JSON.stringify JS 数组发送到 PHP 和 PHP 中的 json_decode
- go - Go Modules - 如何在 GitHub 中引用分支
- node.js - 如何从 express-validator 数组中检索特定项目?