我可以在 tkinter 中使用 rbg 而不是 hex 吗?如果是这样,我该怎么做?我计划使用此功能制作从一种颜色到另一种颜色的渐变,我计划制作一个 for 循环以在几秒钟内将其从 1 更改为 255。
from tkinter import *
root = Tk()
root.configure(background="can i use rgb instead of hex here?")
root.mainloop()
原文由 Morton Madison Wally 发布,翻译遵循 CC BY-SA 4.0 许可协议
不,tkinter 不支持 RGB,但您可以编写一个小的辅助函数来解决这个问题:
也许是这样的,其中参数
rgb
必须是表示为整数元组的有效 rgb 代码。如果您觉得它更具可读性,您还可以使用
fstrings
来获得完全相同的结果:Note that the
colorsys
module from the Python standard library can help translate fromHSV
,HLS
, andYIQ
color systems