当TabOne类Onclick函数被激活时,我想在类TabTwo中运行class函数。在
import wx
class TabOne(wx.Panel):
def __init__(self, parent):
self.button = wx.Button(self, 12, "Submit", wx.Point(300, 590))
wx.EVT_BUTTON(self, 12, self.OnClick)
def OnClick(self, event):
a = TabTwo.getTab2info()
print a
class TabTwo(wx.Panel):
def __init__(self, parent):
self.tb2name= wx.StaticText(self,-1, "The number of pay out years:", wx.Point(20, 190))
self.tb2input=wx.TextCtrl(self, 31, "5",wx.Point(315, 190), wx.Size(150, -1))
@classmethod
def getTab2info(cls):
TabTwo.PayoutYears = self.tb2input.GetValue()
return(TabTwo.PayoutYears)
class MainFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title="Information", size=(1200, 700))
# Create a panel and notebook (tabs holder)
p = wx.Panel(self)
nb = wx.Notebook(p)
# Create the tab windows
tab1 = TabOne(nb)
tab2 = TabTwo(nb)
# Add the windows to tabs and name them.
nb.AddPage(tab1, "Input")
nb.AddPage(tab2, "Model Paramters")
# Set noteboook in a sizer to create the layout
sizer = wx.BoxSizer()
sizer.Add(nb, 1, wx.EXPAND)
p.SetSizer(sizer)
if __name__ == "__main__":
app = wx.App()
MainFrame().Show()
app.MainLoop()
我收到的错误信息如下:
Traceback (most recent call last):
File "C:/Users/a0266997/Documents/Casualty/tbs2.py", line 124, in OnClick3 a = TabTwo.getTab2info()
File "C:/Users/a0266997/Documents/Casualty/tbs2.py", line 224, in getTab2info TabTwo.PayoutYears = self.tb2input.GetValue()
NameError: global name 'self' is not defined
回顾评论。他们给你解决办法。在
这是你的代码修正了。我已经删除了您的评论,并添加了一些新的评论:
祝你好运。在
相关问题 更多 >
编程相关推荐