即使按钮['state']=DISABLED,它也会激活<Button-1>和 <ButtonRelease-1>命令功能 [英] Even if the button ['state']=DISABLED, it activates the <Button-1> and <ButtonRelease-1> command functions

查看:29
本文介绍了即使按钮['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.function1self.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
    ...

这篇关于即使按钮['state']=DISABLED,它也会激活&lt;Button-1&gt;和 &lt;ButtonRelease-1&gt;命令功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆