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)









share|improve this question


















  • 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















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)









share|improve this question


















  • 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













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)









share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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 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














  • 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








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












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()


enter image description here






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    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

























    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()


    enter image description here






    share|improve this answer



























      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()


      enter image description here






      share|improve this answer

























        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()


        enter image description here






        share|improve this answer














        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()


        enter image description here







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 17 at 11:37

























        answered Nov 17 at 11:27









        Miraj50

        1,538517




        1,538517






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

            Alcedinidae

            Origin of the phrase “under your belt”?