我有這個超:如何修復此Python代碼中的錯誤?
進口WX
class Plugin(wx.Panel):
def __init__(self, parent, *args, **kwargs):
wx.Panel.__init__(self, parent, *args, **kwargs)
self.colorOver = ((89,89,89))
self.colorLeave = ((110,110,110))
self.SetBackgroundColour(self.colorLeave)
self.SetForegroundColour(self.colorLeave)
self.name = "plugin"
wx.StaticText(self, -1, self.getName(), style=wx.ALIGN_LEFT)
self.Bind(wx.EVT_ENTER_WINDOW, self.onMouseOver)
self.Bind(wx.EVT_LEAVE_WINDOW, self.onMouseLeave)
def onMouseOver(self, event):
self.SetBackgroundColour(self.colorOver)
self.Refresh()
def onMouseLeave(self, event):
self.SetBackgroundColour(self.colorLeave)
self.Refresh()
def OnClose(self, event):
self.Close()
app.Destroy()
def getName(self):
return self.name
和這個子類:
import plugin
import wx
class noisePlugin(plugin.Plugin):
self.name = "noise"
,這讓我這個錯誤編譯子類:
Traceback (most recent call last):
File "C:\Users\André Ferreira\Desktop\Tese\Código Python\SoundLog\Plugins\noisePlugin.py", line 4, in <module>
class noisePlugin(plugin.Plugin):
File "C:\Users\André Ferreira\Desktop\Tese\Código Python\SoundLog\Plugins\noisePlugin.py", line 5, in noisePlugin
self.name = "noise"
NameError: name 'self' is not defined
能有什麼我確實解決了這個錯誤? 我想讓getName()方法返回實例化類的名字!
感謝提前:)
謝謝m8 :)這是確切的! –
@aF,很高興有幫助! - ) –