如何将Tkinter Button的状态从禁用更改为正常?
我需要状态从改变DISABLED
到NORMAL
的Button
,当一些事件发生。
这是我的按钮的当前状态,当前已禁用:
self.x = Button(self.dialog, text="Download",
state=DISABLED, command=self.download).pack(side=LEFT)
self.x(state=NORMAL) # this does not seem to work
Anyonne可以帮助我该怎么做吗?
-
您只需
state
将您按钮的设置self.x
为normal
:self.x['state'] = 'normal'
要么
self.x.config(state="normal")
此代码将在事件的回调中使用,该事件将导致Button启用。
另外,正确的代码应为:
self.x = Button(self.dialog, text="Download", state=DISABLED, command=self.download) self.x.pack(side=LEFT)
该方法
pack
的Button(...).pack()
回报None
,且将其分配给self.x
。您实际上想要将返回值分配Button(...)
给self.x
,然后在下面的行中使用self.x.pack()
。