默认窗口颜色Tkinter和十六进制颜色代码 [英] Default window colour Tkinter and hex colour codes

查看:3581
本文介绍了默认窗口颜色Tkinter和十六进制颜色代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  root = Tk()我想知道Tkinter的默认窗口颜色。 

如果有一个,可以设置相同的颜色或使用十六进制颜色代码? (使用rgb)



我为'normal'窗口找到的颜色代码是:



R = 240,G = 240,B = 237



谢谢。

解决方案

不确定您要找什么,但是这将工作吗?

  import Tkinter 

mycolor ='#%02x%02x%02x'%(64,204,208)#设置你最喜欢的rgb颜色
mycolor2 ='#40E0D0'#或者如果你喜欢
root = Tkinter, Tg()
root.configure(bg = mycolor)
Tkinter.Button(root,text =Press me!,bg = mycolor,fg ='black',
activebackground =' black',activeforeground = mycolor2).pack()
root.mainloop()

你只需要找到窗口的当前值,并设置窗口小部件使用它, cget 可能是你想要的:

  import Tkinter 

root = Tkinter.Tk()
defaultbg = root.cget('bg')
Tkinter。 Button(root,text =Press me!,bg = defaultbg).pack()
root.mainloop()

如果要为新窗口小部件设置默认背景颜色,可以使用 tk_setPalette(self,* args,** kw)方法:

  root.tk_setPalette(background ='#40E0D0',foreground ='black',
activeBackground ='black ',activeForeground = mycolor2)
Tkinter.Button(root,text =Press me!)pack()

然后你的小部件默认情况下会有这种背景颜色,而不必在窗口小部件参数中设置它。内联帮助函数提供了很多有用的信息 import Tkinter; help(Tkinter.Tk)


I would like to know the default window colour in Tkinter when you simply create a window:

root = Tk()

If there is one, it is possible to set widgets to the same colour or use a hex colour code? (using rgb)

The colour code I have found for the 'normal' window is:

R = 240, G = 240, B = 237

Thanks.

解决方案

Not sure exactly what you're looking for, but will this work?

import Tkinter

mycolor = '#%02x%02x%02x' % (64, 204, 208)  # set your favourite rgb color
mycolor2 = '#40E0D0'  # or use hex if you prefer 
root = Tkinter.Tk()
root.configure(bg=mycolor)
Tkinter.Button(root, text="Press me!", bg=mycolor, fg='black',
               activebackground='black', activeforeground=mycolor2).pack()
root.mainloop()

If you just want to find the current value of the window, and set widgets to use it, cget might be what you want:

import Tkinter

root = Tkinter.Tk()
defaultbg = root.cget('bg')
Tkinter.Button(root,text="Press me!", bg=defaultbg).pack()
root.mainloop()

If you want to set the default background color for new widgets, you can use the tk_setPalette(self, *args, **kw) method:

root.tk_setPalette(background='#40E0D0', foreground='black',
               activeBackground='black', activeForeground=mycolor2)
Tkinter.Button(root, text="Press me!").pack()

Then your widgets would have this background color by default, without having to set it in the widget parameters. There's a lot of useful information provided with the inline help functions import Tkinter; help(Tkinter.Tk)

这篇关于默认窗口颜色Tkinter和十六进制颜色代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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