python tkinter button颜色变不了_更改函数中Tkinter按钮的颜色
我想在按另一個按鈕時改變按鈕的顏色。下面的代碼重新創(chuàng)建屬性錯誤。在
理想情況下,解決方案應(yīng)該能夠更改按鈕的所有屬性(請參閱嘗試的狀態(tài)更改),但我沒有將此添加到標(biāo)題中,因?yàn)槲也恢馈皩傩浴笔欠袷钦_的單詞。在import Tkinter
def tester():
class window(Tkinter.Tk):
def __init__(self,parent):
Tkinter.Tk.__init__(self,parent)
self.parent = parent
self.initialize()
def initialize(self):
self.grid()
button1 = Tkinter.Button(self,text=u"Button")
button1.grid(padx=5,pady=5)
button2 = Tkinter.Button(self,text=u"Change",command=self.colourer)
button2.grid(column=1,row=0,pady=5)
button3 = Tkinter.Button(self,text=u"Disabled",state='disabled')
button3.grid(column=1,row=0,pady=5)
def colourer(self):
self.button1.configure(bg='red')
# self.button1.config(bg='red') -- this gives same error
# self.button3.configure(state='normal') -- as does this
if __name__ == "__main__":
app = window(None)
app.title('Tester')
app.mainloop()
tester()
謝謝
總結(jié)
以上是生活随笔為你收集整理的python tkinter button颜色变不了_更改函数中Tkinter按钮的颜色的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python多线程多进程多协程_pyth
- 下一篇: swift 组件化_打造完备的iOS组件