Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 11th, 2012, 06:06 AM
_rain _rain is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2011
Posts: 6 _rain User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 54 m 44 sec
Reputation Power: 0
Tkinter how to set button bk color and style/exstyle?

Hello.

If I use:
Code:
button = ttk.Button(form, text="Generate", command=generate, bg="black")


then I get this error:
_tkinter.TclError: unknown option "-bg"

Or if I use ttk.Style().configure("TButton", background="red") then it only changes border color.


Edit: is there way to set button style in ttk?
I want to change these styles http://msdn.microsoft.com/en-us/library/windows/desktop/bb775951%28v=vs.85%29.aspx

Reply With Quote
  #2  
Old November 11th, 2012, 08:49 AM
Dietrich's Avatar
Dietrich Dietrich is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 480 Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Days 22 h 8 m 57 sec
Reputation Power: 63
Check the Python manual under ttk
The styling feature is very powerful, but also rather complex.
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25

Last edited by Dietrich : November 11th, 2012 at 09:40 AM.

Reply With Quote
  #3  
Old November 11th, 2012, 09:00 AM
_rain _rain is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2011
Posts: 6 _rain User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 54 m 44 sec
Reputation Power: 0
That doesn't say how to do that. Or at least I couldn't find how.

Reply With Quote
  #4  
Old November 11th, 2012, 09:55 AM
Dietrich's Avatar
Dietrich Dietrich is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 480 Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Days 22 h 8 m 57 sec
Reputation Power: 63
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.

Reply With Quote
  #5  
Old November 11th, 2012, 10:02 AM
_rain _rain is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2011
Posts: 6 _rain User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 54 m 44 sec
Reputation Power: 0
I tried ttk.Style().configure("TButton", relief="flat" ,background="red")


but for some reason I only get border in red. other than that is still default color..... I am using windows..

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Tkinter how to set button bk color?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap