2014-02-20 34 views
0

我想調用函數「function3」,當我點擊按鈕b1(在初始化)。謝謝。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 

回答

0

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

+0

'function3'嵌套在'function1'和'function2'中。 – aIKid

0

你的意思是這樣的嗎?

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只是調用function3function1返回的值將是由function3返回的值。