這是什麼ü想
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)
它在Windows 10的工作100%一個簡單的例子,所以嘗試在Windows 7 我設置顏色爲隨機,這樣你們可以定義每一個與UR「顏色「以瞭解發生了什麼也是highlightbackground
而不是highlightcolor
不知道這會回答你的問題希望它可以幫助你。 http://stackoverflow.com/questions/14264819/how-to-change-colors-of-multiple-widgets-after-hovering-in-tkinter – shivsn
不,這是唯一的談論背景顏色(BG)。我正在尋找與獲得/失去焦點相關的顏色變化(即突出顯示)。 – JDM