How do you update text in an event to be a three number RGB color (ex. 100,100,100) in pysimplegui?

huangapple go评论67阅读模式
英文:

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)))

huangapple
  • 本文由 发表于 2023年3月7日 02:01:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/75654289.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定