在函数python中触发函数

时间:2013-08-08 09:23:32

标签: python function wxpython

我希望能够在按下按钮时从下面示例中的其他两个功能中调用我的第三个功能。如何保持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()

1 个答案:

答案 0 :(得分: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