2013-08-08 5 views
0

Я хочу, чтобы иметь возможность вызвать мою третью функцию в игру из двух других функций в приведенном ниже примере всякий раз, когда вы нажимаете кнопки. Как я могу это сделать, сохраняя значение для s?Запуск функции внутри функции python

import wx 

class MyDialog(wx.Dialog): 
    def __init__(self, parent, id, title): 
     wx.Dialog.__init__(self, parent, id, title, wx.DefaultPosition, wx.Size(350, 100)) 


     wx.Button(self, 1, '1', (100, 10)) 
     wx.Button(self, 2, '2', (185, 10)) 

     self.Bind(wx.EVT_BUTTON, self.one, id=1) 
     self.Bind(wx.EVT_BUTTON, self.two, id=2) 


    def one(self,event): 
     s=1 



    def two(self,event): 
     s=2 

    def three(self,event): 
     print s 

class MyApp(wx.App): 
    def OnInit(self): 
     dlg = MyDialog(None, -1, 'Example') 

     dlg.Show(True) 
     dlg.Centre() 

     return True 

app = MyApp(0) 

app.MainLoop() 

ответ

1

Просто позвоните thee в self.three(value):

def one(self, event): 
    self.three(1) 

def two(self, event): 
    self.three(2) 

def three(self, s): 
    print s 
Смежные вопросы