我正在尝试这样
import wx
import gui
from xml.dom.minidom import parse
class MainFrame(gui.MainFrame):
def __init__(self, parent):
dom = parse("data.xml")
data = dom.getElementById("album")
self.m_textCtrl2.SetValue(data)
我在gui中定义了m_textCrtl2,这是主init
if __name__ == "__main__":
app = wx.App(False)
mainFrame = MainFrame(None)
app.SetTopWindow(mainFrame)
mainFrame.Show()
app.MainLoop()
和追溯
Traceback (most recent call last):
File "CDBase.py", line 40, in <module>
mainFrame = MainFrame(None)
File "CDBase.py", line 16, in __init__
self.m_textCtrl2.SetValue(data)
AttributeError: 'MainFrame' object has no attribute 'm_textCtrl2'
我是python的新手,所以我将不胜感激任何帮助:)
答案 0 :(得分:2)
class MainFrame(gui.MainFrame):
def __init__(self, parent):
dom = parse("data.xml")
data = dom.getElementById("album")
self.m_textCtrl2.SetValue(data)
你没有调用超类的构造函数。你需要明确地调用它。
class MainFrame(gui.MainFrame):
def __init__(self, parent):
super(MainFrame, self).__init__(whatever, arguments, but, not, self)
dom = parse("data.xml")
data = dom.getElementById("album")
self.m_textCtrl2.SetValue(data)