当前位置:   article > 正文

tkinter 设置不可编辑_如何将Tkinter Button的状态从禁用更改为正常?

tkinter禁用button

I need to change the state from DISABLED to NORMAL of a Button when some event occurs.

Here is the current state of my Button, which is currently disabled:

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

Can anyonne help me on how to do that?

解决方案

You simply have to set the state of the your button self.x to normal:

self.x['state'] = 'normal'

or

self.x.config(state="normal")

This code would go in the callback for the event that will cause the Button to be enabled.

Also, the right code should be:

self.x = Button(self.dialog, text="Download", state=DISABLED, command=self.download)

self.x.pack(side=LEFT)

The method pack in Button(...).pack() returns None, and you are assigning it to self.x. You actually want to assign the return value of Button(...) to self.x, and then, in the following line, use self.x.pack().

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/125002
推荐阅读
相关标签
  

闽ICP备14008679号