简体   繁体   中英

Default color of button Tkinter

What is the default button color's name? The color that appears if you don't enter any color like in bg. I want to delete the bg I entered during the program to the default color so it will look like it did in the beginning.

Thanks!

As @jasonharper wrote in the comments. Since the default color is different between operating systems, the easiest way to reset the button color is to fetch and store it before setting it to some other color. Then you could simply use this value to reset the button to its default color.

import tkinter

root = tkinter.Tk()

button = tkinter.Button(root, text='Hello')
DEFAULT_BUTTON_COLOR = button['bg']
button['bg'] = 'blue'
button.pack()

# Somewhere in your code where you want to reset the color
button['bg'] = DEFAULT_BUTTON_COLOR

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