sca*_*ous 33 python state tkinter button
我需要状态从改变DISABLED到NORMAL的Button,当一些事件发生.
这是我的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
Run Code Online (Sandbox Code Playgroud)
anyonne可以帮助我如何做到这一点?
She*_*eng 60
您只需state将按钮设置self.x为normal:
self.x['state'] = 'normal'
Run Code Online (Sandbox Code Playgroud)
要么
self.x.config(state="normal")
Run Code Online (Sandbox Code Playgroud)
此代码将进入将导致启用Button的事件的回调.
此外,正确的代码应该是:
self.x = Button(self.dialog, text="Download", state=DISABLED, command=self.download)
self.x.pack(side=LEFT)
Run Code Online (Sandbox Code Playgroud)
该方法pack的Button(...).pack()回报None,且将其分配给self.x.实际上,你要分配的返回值Button(...)来self.x,然后在下面的行,使用self.x.pack().
小智 7
我认为更改窗口小部件选项的快速方法是使用该configure方法.
在你的情况下,它看起来像这样:
self.x.configure(state=NORMAL)
Run Code Online (Sandbox Code Playgroud)