user2543008
user2543008

Reputation: 7

Triggering a function within a function python

I want to be able to call my third function into play from within the other two functions in the example below whenever you press the buttons. How can I do this while keeping the value for s?

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()

Upvotes: 0

Views: 62

Answers (1)

falsetru
falsetru

Reputation: 369064

Just call thee as self.three(value):

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

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

def three(self, s):
    print s

Upvotes: 1

Related Questions