英文:
How do you update text in an event to be a three number RGB color (ex. 100,100,100) in pysimplegui?
问题
我想创建一个根据程序中先前找到的像素而更改颜色的文本,但我不知道如何将RGB颜色(例如100,100,100)转换为PySimpleGUI上的颜色。有没有办法做到这一点?
elif event == "PDF Icon Color":
print("查找颜色")
window["PDF"].update(text_color=(100, 100, 100))
英文:
I want to make text that changes color depending on a pixel that was found earlier in the program but I cannot figure out how to turn an RGB color (ex. 100,100,100) into a color on pysimplegui. Is there any way to do that?
elif event == "PDF Icon Color":
print("Finding color")
window["PDF"].update(text_color = (100,100,100))
答案1
得分: 0
PySimpleGUI看起来接受十六进制颜色值,因此您可以首先将RGB值转换为十六进制:
def rgb_to_hex(rgb):
return '%02x%02x%02x' % rgb
rgb_to_hex((255, 255, 195)) #返回 ffffc3
然后您可以使用您的代码:
window["PDF"].update(text_color = rgb_to_hex((100,100,100)))
我不太确定是否需要在十六进制值前加上#,如果需要的话:
window["PDF"].update(text_color = "#" + rgb_to_hex((100,100,100)))
英文:
PySimpleGUI looks like it takes colours as hex values, so you can convert the rgb value into hex first:
def rgb_to_hex(rgb):
return '%02x%02x%02x' % rgb
rgb_to_hex((255, 255, 195)) #returns ffffc3
Then you can use your code:
window["PDF"].update(text_color = rgb_to_hex((100,100,100)))
I'm not too sure if the # is required for hex values, if it is:
window["PDF"].update(text_color = "#" + rgb_to_hex((100,100,100)))
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论