Python 通过自身值更改tkinter中按钮的状态

Python 通过自身值更改tkinter中按钮的状态,python,user-interface,button,tkinter,state,Python,User Interface,Button,Tkinter,State,我有一个类GUI,用几个小部件创建一个tk窗口 我希望保存按钮的状态根据几个self的值而改变 在def初始化中: btn_save['state']='disabled' if self.basepath and (self.variable.get() == 0 or self.variable.get() =='1) and (self.secondOpt.get() == '0 or self.secondOpt.get() == 1): btn_save['state'

我有一个类GUI,用几个小部件创建一个tk窗口 我希望保存按钮的状态根据几个self的值而改变

在def初始化中:

btn_save['state']='disabled'
if self.basepath and (self.variable.get() == 0 or self.variable.get() =='1) and (self.secondOpt.get() == '0 or self.secondOpt.get() == 1):
        btn_save['state']='normal' #here I want to change the save button state
主程序:

window = Tk()
my_gui = GUI(window)
window.mainloop()

我该怎么做?

使用
之后的
方法,如下所示:

def state_change():
'''your code here'''
if self.basepath and (self.variable.get() == 0 or self.variable.get() =='1) and (self.secondOpt.get() == '0 or self.secondOpt.get() == 1):
    btn_save['state']='normal' #here I want to change the save button state
    root.after(100, state_change) #if you want to keep changing the state of the button
root.after(100, state_change)


使用
按钮
小部件专门更改它(您不需要的东西)

因此我需要通过命令将它绑定到小部件,或者我应该在几个小部件中插入此方法吗?这可以添加到
初始化
方法中。使回调方法成为类方法。只有在您对方法感到满意的情况下,才能嵌套这些方法