我可以在Tkinter中使用rgb吗? [英] Can i use rgb in tkinter?

查看:310
本文介绍了我可以在Tkinter中使用rgb吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在tkinter中使用rbg而不是hex吗?如果是这样,我该怎么办?
我打算使用此功能使某种颜色从一种颜色过渡到另一种颜色,并且我打算进行for循环以在几秒钟内将其从1更改为255。

Can I use rbg instead of hex in tkinter? If so, how can I do it? I am planning to use this feature to make sort of a gradient from one color to another and I plan to make a for loop to change it from 1 to 255 in a few seconds.

from tkinter import *

root = Tk()
root.configure(background="can i use rgb instead of hex here?")
root.mainloop()


推荐答案

不,tkinter不支持RGB,但是您可以编写一个小的辅助函数来对此进行补救:

No, tkinter does not support RGB, but you can write a small helper function to remedy this:

也许是这样的,其中参数 rgb 必须是表示为整数元组的有效rgb代码。

Maybe something like this, where the argument rgb must be a valid rgb code represented as tuple of integers.

import tkinter as tk


def _from_rgb(rgb):
    """translates an rgb tuple of int to a tkinter friendly color code
    """
    return "#%02x%02x%02x" % rgb   

root = tk.Tk()
root.configure(bg=_from_rgb((0, 10, 255))) 
root.mainloop()

这篇关于我可以在Tkinter中使用rgb吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆