This is a simple example of what you want.
from Tkinter import * from time import sleep from random import choice class TestColor(): def __init__(self): self.root = Tk() self.button = Button(self.root, text = "buggton", command = self.ChangeColor, bg = "green", fg = "Black", activebackground = "Red", highlightbackground="Black") self.button.grid(row=0, column=0) self.RanDomiZeColor = ["blue", "black", "white", "yellow"] self.root.mainloop() def ChangeColor(self): self.button = Button(self.root, text = "buggton", command = self.ChangeColor, bg = choice(self.RanDomiZeColor), fg = choice(self.RanDomiZeColor), activebackground = choice(self.RanDomiZeColor), highlightbackground = choice(self.RanDomiZeColor)) self.button.grid(row=0, column=0) try: TestColor() except Exception as why: print why; sleep(10)
It works 100% on Windows 10. so try it on Windows 7 I set the color randomly, so you can define each with ur βcolorβ to understand what happened and it highlightbackground not highlightcolor
source share