2014-12-04 94 views
2

在我的程序中,我在按鈕中使用圖片。如果我現在用button.configure(state="disabled")禁用此按鈕,我會在整個按鈕上覆蓋一層白色。我可以刪除此覆蓋嗎?如果是的話如何?提前致謝。下面是一個例子代碼:Python Tkinter刪除禁用的按鈕覆蓋

import Tkinter as tk 

window = tk.Tk() 

def disable(): 
    button1.config(state="disabled") 

button1=tk.Button(command=disable) 
testbild=tk.PhotoImage(file="testbild.gif") 
button1.image=testbild 
button1.configure(relief="flat", image=testbild, height=180, width=180, 
         background="lightgreen", activebackground="lightgreen", bd=0) 
button1.pack() 

window.mainloop() 
+1

我認爲這是Tkinter的中不可避免的一個方面。有人在這個問題[這裏](http://stackoverflow.com/questions/11366349/tkinter-color-of-disabled-buttons-disabled-optionmenus)提出了一個解決方法,你可以嘗試。 – Ajean 2014-12-04 20:54:00

+2

您有使用按鈕的原因嗎?如果你想要一個圖像在用戶點擊時不做任何事情,只需將圖像添加到標籤。禁用的效果是爲了達到目的,提醒用戶他們無法做到他們期望能夠做的事情。 – 2014-12-04 20:56:24

回答

0

您可以通過按鈕創建時設置背景顏色改變點畫的顏色:

button1=tk.Button(command=disable, bg='black') 
+0

嗯,這並不能幫助我。通過這段代碼,我可以改變覆蓋層的顏色,但實際上我想完全移除覆蓋層。 – Duardo 2014-12-07 15:28:55