
November 11th, 2012, 09:55 AM
|
 |
Contributing User
|
|
|
|
Sorry, the manual tells
Quote: background =
Windows and Mac have a notion of an “active” or foreground window.
The background state is set for widgets in a background window, and
cleared for those in the foreground window |
Code:
'''ttk_button_label1.py
a look at foreground/background colors
'''
try:
# Python27
import Tkinter as tk
import ttk
except ImportError:
# Python31+
import tkinter as tk
import tkinter.ttk as ttk
root = tk.Tk()
# typical tk button
tk_btn = tk.Button(text="tk_Sample", bg='black', fg='red')
tk_btn.pack(pady=10)
# now a ttk button with styling (bg/fg won't do)
ttk.Style().configure("RB.TButton", foreground='red', background='black')
ttk_btn = ttk.Button(text="ttk_Sample", style="RB.TButton")
ttk_btn.pack(pady=10)
# foreground/background works with a ttk label but not a ttk button
# the way you expect
style = ttk.Style()
style.configure("GB.TLabel", foreground="green", background="blue")
ttk_label = ttk.Label(text="ttk_Label", style="GB.TLabel")
ttk_label.pack(pady=10)
root.mainloop()
I am lost with this background thing. In desperation, you could put a label on the button instead of text. Have enough of the button show so it can be clicked.
Last edited by Dietrich : November 11th, 2012 at 10:33 AM.
|