即使按钮['state']=DISABLED,它也会激活<Button-1>和 <ButtonRelease-1>命令功能
我为自己制作了一个程序,其中有多个按钮,我需要这些按钮在它们被释放时向我发送命令.
I made myself a program in which I have multiple buttons and I need that buttons to send me a command when they are released.
self.predefined_1_button=Button(self.Background_Main, text="Predefined 1", width=10, heigh=2)
self.predefined_1_button.place(anchor='nw', x=10,y=100)
self.predefined_1_button['state']=DISABLED
self.predefined_1_button.bind('<Button-1>',self.function1)
self.predefined_1_button.bind('<ButtonRelease-1>',self.function2)
在程序开始时,按钮的默认状态是禁用(变灰),如果我点击它,函数 1 和函数 2 正在激活.
At the start of the program the default state of the button is DISABLED (grayed out) and if I click on it the function1 and function2 are activating.
您有任何想法或解决方法吗?
Do you have any ideeas or workarounds?
在调用分配给 command
属性的函数时,状态被正确管理.如果您绕过 command
属性并添加自己的绑定,则由您来检查小部件的状态.
The state is managed properly when calling the function assigned to the command
attribute. If you bypass the command
attribute and add your own bindings, it is up to you to check the state of the widget.
你需要修改self.function1
和self.function2
来检查状态,只有状态正常才做它们的功能.
You will need to modify self.function1
and self.function2
to check the state, and only do their function if the state is normal.
def self.function1(self, event):
if event.widget.cget("state") == "disabled":
return
...