How do I change the colour of my button and label on Tkinter?

后端 未结 4 484
盖世英雄少女心
盖世英雄少女心 2021-01-26 12:35

My task is to create a label and button on Tkinter. The button has to change the label, and I have to change the colour of the button and the label. I have changed the colour of

4条回答
  •  旧时难觅i
    2021-01-26 13:08

    On Windows 10, I have run into the same problem, and have found a solution, although not a very satisfying one. The following will create a black button with white foreground type:

    First define a custom button style based on the standard TButton style

    mystyle = ttk.Style()
    mystyle.configure('mycustom.TButton',background='black',foreground='white')
    

    Then create the button using the new custom style

    mybutton = ttk.Button(root,style='mycustom.Tbutton')
    

    I say 'not very satisfying' because this only works if I have previously set the overall theme to 'default' as follows:

    mystyle = ttk.Style()
    mystyle.theme_use('default')
    

    Using any of the other themes available on my system (winnative,clam,alt,classic,vista and xpnative) will change only the border to black, and leave the background grey.

提交回复
热议问题