Python 如果用户单击checkbutton,如何启用按钮

Python 如果用户单击checkbutton,如何启用按钮,python,python-3.x,tkinter,tkinter.checkbutton,Python,Python 3.x,Tkinter,Tkinter.checkbutton,这是我的密码 def register_user(): Button(win, text="Sign Up", command=register_file, state=DISABLED).place(x=20, y=290) var = IntVar() Checkbutton(win, variable=var,).place(x=15, y=249) 如何执行此操作这非常简单,您可以使用Checkbutton的命令选

这是我的密码

def register_user():

        Button(win, text="Sign Up", command=register_file, state=DISABLED).place(x=20, y=290) 
        var = IntVar()
        Checkbutton(win, variable=var,).place(x=15, y=249)

如何执行此操作

这非常简单,您可以使用
Checkbutton
命令
选项,在每次选中或取消选中复选框时获取一个要触发的func,如:

def register_user():
        def enable(*args):
            if var.get(): #if the checkbutton is tick
                b['state'] = 'normal' #enable the button
            else: #else
                b['state'] = 'disabled' #disable it

        but = Button(win, text="Sign Up", command=register_file, state=DISABLED)
        but.place(x=20, y=290) 
        var = IntVar()
        cb = Checkbutton(win, variable=var,command=enable) #command option triggers the enable
        cb.place(x=15, y=249)
为什么我要在另一行上指定变量和
place()
?这样小部件就不会变成
None

Entry对象和所有其他小部件的grid、pack和place函数都不返回任何值。在python中,执行a().b()时,表达式的结果是b()返回的结果,因此条目(…).grid(…)将不返回任何结果


为了更好地理解从其源代码读取,这非常简单,您可以使用
Checkbutton
命令
选项,在每次选中或取消选中复选框时获取要触发的func,如:

def register_user():
        def enable(*args):
            if var.get(): #if the checkbutton is tick
                b['state'] = 'normal' #enable the button
            else: #else
                b['state'] = 'disabled' #disable it

        but = Button(win, text="Sign Up", command=register_file, state=DISABLED)
        but.place(x=20, y=290) 
        var = IntVar()
        cb = Checkbutton(win, variable=var,command=enable) #command option triggers the enable
        cb.place(x=15, y=249)
为什么我要在另一行上指定变量和
place()
?这样小部件就不会变成
None

Entry对象和所有其他小部件的grid、pack和place函数都不返回任何值。在python中,执行a().b()时,表达式的结果是b()返回的结果,因此条目(…).grid(…)将不返回任何结果


为了更好地理解,请阅读其来源,

谢谢您的回答谢谢您的回答