python tkinter button颜色变不了_更改函数中Tkinter按钮的颜色

我想在按另一个按钮时改变按钮的颜色。下面的代码重新创建属性错误。在

理想情况下,解决方案应该能够更改按钮的所有属性(请参阅尝试的状态更改),但我没有将此添加到标题中,因为我不知道“属性”是否是正确的单词。在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()

谢谢

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值