Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default window colour Tkinter and hex colour codes

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.

like image 640
user2063 Avatar asked Jul 05 '12 08:07

user2063


People also ask

What is the default color of Tkinter window?

The default background color of a GUI with Tkinter is grey. You can change that to any color based on your application's requirement.

Can I use hex colors in Tkinter?

You can use a string specifying the proportion of red, green and blue in hexadecimal digits. For example, "#fff" is white, "#000000" is black, "#000fff000" is pure green, and "#00ffff" is pure cyan (green plus blue). You can also use any locally defined standard color name.

Does Python use hex colors?

Python turtle has predefined colours such as 'red' and 'white' but you can also use hex colour codes (you may have seen these in the HTML & CSS course.)

Can I use RGB in Tkinter?

Build A Paint Program With TKinter and Python To set the background color or foreground color of a widget, we can use both default and RGB color codes. RGB is defined by the 6 digit alphanumeric character containing different digits of R, G, B values.


2 Answers

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)

like image 68
rudivonstaden Avatar answered Sep 30 '22 03:09

rudivonstaden


The default color for Tkinter window I found was #F0F0F0

like image 30
Alex Efron Avatar answered Sep 30 '22 03:09

Alex Efron