简体   繁体   中英

Python: Set Color for Tkinter Button using .grid()

using the Python 2.7 Tkinter Grid Layouter, i would like to do something like

root.button = Button(root, bg = 'green', ....)
root.button.grid(...)

in order to get a green button. Running this, it doesn't bring up any errors, but the button does not take the desired color. Any suggestions greatly appreciated!

EDIT: thanks for the code, i copied it and run it, here is what i get: still a white button ..? 在此处输入图片说明

Passing bg keyword argument works as expected. Try following:

from Tkinter import *
root = Tk()
button = Button(root, text='buggton', bg='green')
button.grid(row=0, column=0)
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