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
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
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.
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.
精彩评论