Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python : Tkinter widget background (buttons, entries etc)

Tags:

python

tkinter

I'm having a bit of a problem in creating my GUI's. It's when changing backgrounds, I can change the whole background, and also the background of the labels and such, but when it comes to buttons and entry fields etc, there is a white area behind the button that i cannot seem to change :S

The problem can be seen in the picture below.

(Don't have enough reputation to post picture, so will link it) http://www.thesite.dk/upload/media/tkinter.png

With the code :

from Tkinter import *

background = "BLACK"
textColor = "WHITE"
root = Tk()
root.configure(bg=background)

Email = Label(root, text="Enter E-mail Address :", font=("Lucida Grande", 12), fg=textColor, background=background)
Email.grid(row=6, column=0, sticky=NW, padx=19)

EmailField = Entry(root, width=30)
EmailField.grid(row=6, column=0, columnspan=3, sticky=NW, padx=159)

EmailButton = Button(root, text="Mail It !", background=background)
EmailButton.grid(row=6, column=0, columnspan=6, sticky=NW, padx=389)

SM_Status = StringVar()
EmailStatus = Label(root, textvariable=SM_Status, font=("Lucida Grande", 12), fg=textColor, background=background)
EmailStatus.grid(row=6, column=2, sticky=NW, padx=20)

There may be a simple solution, but countless googles and hours of reading documentation and forum posts has gotten me nowhere :( I hope youre able to help...

And yes, I'm using Mac OS X with python 2.6

like image 279
Tehnix Avatar asked Apr 13 '11 23:04

Tehnix


2 Answers

I know it's been a while and you're certainly no longer working on this code, but I found a solution, and I'll post it here for everybody who has a similar issue. It's the same as the way you get the area around an entry to be your background color:

highlightbackground=color

like image 72
Peter Avatar answered Sep 29 '22 00:09

Peter


On the macintosh there's not much you can do about the background color of native buttons. Such is the price we pay for native buttons. On other platforms and for other widgets, what you are seeing is probably the "highlight background" which can be modified with the highlightbackground and highlightthickness attributes of a widget. This is the area used by the widget to denote focus.

like image 39
Bryan Oakley Avatar answered Sep 28 '22 23:09

Bryan Oakley