简体   繁体   中英

How to change default background colour in tkinter

I want to have all my labels and buttons to have a white background. I know I can use bg="white" in each one but I was thinking if there was a way I could change the default colour to white or make it so that all widgets have a white background with a single line of code. similar to how you can change the font by doing:

from tkinter import *
window=Tk()
window.option_add("*font",("Arial",15))
window.mainloop()

Which will set all the font to Arial 15

thanks to @acw1668 's comment, can do window.option_add("*Label*Background", "white") and window.option_add("*Button*Background", "white") to solve it. Just thought id put it as an answer in case people don't see the comment and what not.

Unfortunately, as far as I'm aware there is no such natively supported function. However, you could make your own custom method to do just this. Here's an idea of what I'm talking about:

def whiteButton(window, text, fg):
  return Button(window, text = text, bg='white', fg=fg)

I hope that was helpful:)

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