簡體   English   中英

python調用函數,當我單擊按鈕時

[英]python call function, when I click on button

當我單擊按鈕b1(位於init )時,我想調用函數“ function3”。 謝謝。

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

您可能不應該在函數中定義函數。 通常,如果內部函數僅由外部函數使用,則在另一個函數中定義一個函數只是一個好主意。 尋找另一種解決問題的方法,而無需從外部調用嵌套函數。

你的意思是這樣的嗎?

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 ,而function2只是調用function3 的返回值function1將是返回的值function3

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM