5

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

Tehnix
  • 2,020
  • 2
  • 18
  • 23
  • I'm guessing you're on a Mac? Under Linux (Python2.7, Tkinter 81008), I get a rectangular black button with a white border. When I mouse over it (activate it), it becomes gray. – Mark Apr 14 '11 at 01:06
  • @Mark - Yes, I'm on a mac but can't really see how the mouse over (activation) would solve my problem since it is consistent from startup of the application. Thx for the input though :) – Tehnix Apr 14 '11 at 07:56

3 Answers3

10

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

Mayur Birari
  • 5,837
  • 8
  • 34
  • 61
Peter
  • 116
  • 1
  • 2
  • 1
    Dug up my old code and checked so I could approve your answer, and yeah, your solution worked :) Although a bit late (and correct that I'm not working on it anymore) it will perhaps help others in the same position as I was. Thanks! :) – Tehnix Dec 03 '12 at 14:52
2

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.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • would it help to use another GUI creator instead of Tkinter, or is it actually possible to change the design of the button itself? – Tehnix Apr 14 '11 at 19:33
1

This seems to be platform dependent, and maybe theme dependent within that. I'm guessing you're on a Mac by the way the button looks in your screen shot. It seems the button text is drawn within a bitmap that provides the rounded outline of the button. It may not be within Tkinter's capability to control that.

On Windows with the classic theme, the button background is black but there is a gray outline due to the relief being raised. When I set it to relief=FLAT, it is completely black.

It would be helpful if your included sample was directly runnable. I had to add a definition for textColor, comment out command=CMD.send_mail, and add root.mainloop() at the end. I also added textColor=WHITE to the button setup.

Try playing with the relief option, or change your system's theme to see if you can affect the way the button is drawn.

Todd
  • 5,999
  • 2
  • 21
  • 21
  • Tried to play around with the relief option a little, but can't really get this to solve my problem :( – Tehnix Apr 14 '11 at 07:49