简体   繁体   中英

Tkinter button color

When I create a button like this in tkinter:

self.submition_button=Button(self.root, text='Submit', 
            font='Times 12 bold italic', command=self.onSubmition, bg='blue')

the button isn't blue.

Why isn't it blue, and what can I do to make it blue?

Are you using tkinter.Button or are you really using ttk.Button? You'll know which one your using based on what you imported in the top of code

regular tkinter widgets importing

import tkinter

typical TTK widgets importing

from tkinter import ttk

Because TTK is more modern version of the library it's styling system is different. So setting flag options on it wont work. instead you have to use style theme.

See this reply.

https://stackoverflow.com/a/44416355/8661716

This is the code for a blue button, check it :

from tkinter import *

#create a window
root =Tk()

button=Button(root, text='Submit',  font='Times 12 bold italic', bg='blue', activebackground="blue")
button.pack()
root.mainloop()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM