Cannot change color of button in Tkinter
up vote
-1
down vote
favorite
I am not able to change the color of the button using fg and bg. I get this error: "_tkinter.TclError: unknown option "-fg""
_scrape_btn = ttk.Button(
_mainframe, text='Scrape!', command=save
)
_scrape_btn.grid(row=2, column=0, sticky=(N,E), pady=2)
_compress_btn = ttk.Button(
_mainframe, text='Compress!', command=compress
)
_compress_btn.grid(row=2, column=1, sticky=W, pady=2)
python tkinter
add a comment |
up vote
-1
down vote
favorite
I am not able to change the color of the button using fg and bg. I get this error: "_tkinter.TclError: unknown option "-fg""
_scrape_btn = ttk.Button(
_mainframe, text='Scrape!', command=save
)
_scrape_btn.grid(row=2, column=0, sticky=(N,E), pady=2)
_compress_btn = ttk.Button(
_mainframe, text='Compress!', command=compress
)
_compress_btn.grid(row=2, column=1, sticky=W, pady=2)
python tkinter
1
I might be missing something but in the code you've provided there is no setting of colour whatsoever. Please provide the code where you are actually doing that.
– rbaleksandar
Nov 17 at 10:52
@rbaleksandar The OP most probably tried to put it as a parameter in thettk.Button
function, but got an error. So removed it and probably presented the code that was working. I will propose an edit to change it which would give an error.
– Miraj50
Nov 17 at 11:58
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I am not able to change the color of the button using fg and bg. I get this error: "_tkinter.TclError: unknown option "-fg""
_scrape_btn = ttk.Button(
_mainframe, text='Scrape!', command=save
)
_scrape_btn.grid(row=2, column=0, sticky=(N,E), pady=2)
_compress_btn = ttk.Button(
_mainframe, text='Compress!', command=compress
)
_compress_btn.grid(row=2, column=1, sticky=W, pady=2)
python tkinter
I am not able to change the color of the button using fg and bg. I get this error: "_tkinter.TclError: unknown option "-fg""
_scrape_btn = ttk.Button(
_mainframe, text='Scrape!', command=save
)
_scrape_btn.grid(row=2, column=0, sticky=(N,E), pady=2)
_compress_btn = ttk.Button(
_mainframe, text='Compress!', command=compress
)
_compress_btn.grid(row=2, column=1, sticky=W, pady=2)
python tkinter
python tkinter
asked Nov 17 at 10:46
user162817
84
84
1
I might be missing something but in the code you've provided there is no setting of colour whatsoever. Please provide the code where you are actually doing that.
– rbaleksandar
Nov 17 at 10:52
@rbaleksandar The OP most probably tried to put it as a parameter in thettk.Button
function, but got an error. So removed it and probably presented the code that was working. I will propose an edit to change it which would give an error.
– Miraj50
Nov 17 at 11:58
add a comment |
1
I might be missing something but in the code you've provided there is no setting of colour whatsoever. Please provide the code where you are actually doing that.
– rbaleksandar
Nov 17 at 10:52
@rbaleksandar The OP most probably tried to put it as a parameter in thettk.Button
function, but got an error. So removed it and probably presented the code that was working. I will propose an edit to change it which would give an error.
– Miraj50
Nov 17 at 11:58
1
1
I might be missing something but in the code you've provided there is no setting of colour whatsoever. Please provide the code where you are actually doing that.
– rbaleksandar
Nov 17 at 10:52
I might be missing something but in the code you've provided there is no setting of colour whatsoever. Please provide the code where you are actually doing that.
– rbaleksandar
Nov 17 at 10:52
@rbaleksandar The OP most probably tried to put it as a parameter in the
ttk.Button
function, but got an error. So removed it and probably presented the code that was working. I will propose an edit to change it which would give an error.– Miraj50
Nov 17 at 11:58
@rbaleksandar The OP most probably tried to put it as a parameter in the
ttk.Button
function, but got an error. So removed it and probably presented the code that was working. I will propose an edit to change it which would give an error.– Miraj50
Nov 17 at 11:58
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
The reason this is happening is because you are using ttk.Button
instead of tk.Button
. The options such as fg
, bg
are not supported by ttk. Instead you will have to use Style
option and configure it as you require. Here is an example.
import tkinter as tk
import tkinter.ttk as ttk
root = tk.Tk()
style = ttk.Style()
style.configure("TButton", foreground="blue", background="orange")
myButton = ttk.Button(text="Scrape", style="TButton")
myButton.grid()
root.mainloop()
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
The reason this is happening is because you are using ttk.Button
instead of tk.Button
. The options such as fg
, bg
are not supported by ttk. Instead you will have to use Style
option and configure it as you require. Here is an example.
import tkinter as tk
import tkinter.ttk as ttk
root = tk.Tk()
style = ttk.Style()
style.configure("TButton", foreground="blue", background="orange")
myButton = ttk.Button(text="Scrape", style="TButton")
myButton.grid()
root.mainloop()
add a comment |
up vote
2
down vote
accepted
The reason this is happening is because you are using ttk.Button
instead of tk.Button
. The options such as fg
, bg
are not supported by ttk. Instead you will have to use Style
option and configure it as you require. Here is an example.
import tkinter as tk
import tkinter.ttk as ttk
root = tk.Tk()
style = ttk.Style()
style.configure("TButton", foreground="blue", background="orange")
myButton = ttk.Button(text="Scrape", style="TButton")
myButton.grid()
root.mainloop()
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
The reason this is happening is because you are using ttk.Button
instead of tk.Button
. The options such as fg
, bg
are not supported by ttk. Instead you will have to use Style
option and configure it as you require. Here is an example.
import tkinter as tk
import tkinter.ttk as ttk
root = tk.Tk()
style = ttk.Style()
style.configure("TButton", foreground="blue", background="orange")
myButton = ttk.Button(text="Scrape", style="TButton")
myButton.grid()
root.mainloop()
The reason this is happening is because you are using ttk.Button
instead of tk.Button
. The options such as fg
, bg
are not supported by ttk. Instead you will have to use Style
option and configure it as you require. Here is an example.
import tkinter as tk
import tkinter.ttk as ttk
root = tk.Tk()
style = ttk.Style()
style.configure("TButton", foreground="blue", background="orange")
myButton = ttk.Button(text="Scrape", style="TButton")
myButton.grid()
root.mainloop()
edited Nov 17 at 11:37
answered Nov 17 at 11:27
Miraj50
1,538517
1,538517
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53350464%2fcannot-change-color-of-button-in-tkinter%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
I might be missing something but in the code you've provided there is no setting of colour whatsoever. Please provide the code where you are actually doing that.
– rbaleksandar
Nov 17 at 10:52
@rbaleksandar The OP most probably tried to put it as a parameter in the
ttk.Button
function, but got an error. So removed it and probably presented the code that was working. I will propose an edit to change it which would give an error.– Miraj50
Nov 17 at 11:58