2016-02-04 19 views
5

我正在構建Tkinter GUI(Python 2.7)並在Win7機器上運行它。我想要做的事情之一就是當按鈕&複選框被突出顯示時(在高亮標記本身有點暈,特別是使用默認灰色背景時)會採用不同的顏色。但是,將highlightcolor設置爲不同的顏色(例如'cyan')對GUI沒有任何影響;無論焦點與否,控件都保持灰色。作爲交叉檢查,我嘗試將所有highlightblah選項設置爲不同,但仍顯示爲灰色,厚度也沒有明顯變化。Winkin上的Tkinter highlightcolor選項

這是Tkinter在Win7上的一個限制嗎?它只是沒有迴應這些選項?

+0

不知道這會回答你的問題希望它可以幫助你。 http://stackoverflow.com/questions/14264819/how-to-change-colors-of-multiple-widgets-after-hovering-in-tkinter – shivsn

+0

不,這是唯一的談論背景顏色(BG)。我正在尋找與獲得/失去焦點相關的顏色變化(即突出顯示)。 – JDM

回答

0

這是什麼ü想

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

+0

這不是一個真正有用的例子......它每次點擊都會實例化一個新按鈕,新按鈕直接放在舊的按鈕的頂部並覆蓋它,並且只有太多的「噪音」總體來說,將隨機顏色更改應用於每個顏色選項,而不僅僅是我所關注的高亮顏色選項。所有這一切,並沒有完成我最初在Win7上所要求的:當我將亮點移到或離開它時,仍然沒有發生顏色變化發生在按鈕上。 – JDM