python调用函数,当我单击按钮时

2024-04-24 14:16:31 发布

您现在位置:Python中文网/ 问答频道 /正文

在“函数”中点击按钮。非常感谢。在

class myClass():
    def __init__(self):
        b1 = Button(self.ram2C, text="Aaa", command=???function3???)


    def function1(self, event=None):
        command1

        def function2(event):
            command2

            def function3 (event=None):
               command3

Tags: 函数textselfnoneeventinitdefmyclass
4条回答

你是说像这样的?在

b1 = Button(self.ram2C, text="Aaa", command=function1)
def function1(self, event=None):
        command1
        def function2(event):
            command2
            def function3 (event=None):
               command3
            return function3(event)
        return function2(event)

简而言之,function1正在调用function2,而{}只是调用function3function1返回的值将是function3返回的值。在

您可能不应该在函数中定义函数。一般来说,如果内部函数只由外部函数使用,那么在另一个函数中定义函数才是一个好主意。找到另一种解决问题的方法,而不需要从外部调用嵌套函数。在

相关问题 更多 >