AttributeError: 'WindowManager' object has no attribute 'createWindow'
AttributeError: 'WindowManager' object has no attribute 'createWindow'
这是两个代码块:
class WindowManager(object):
def __init__(self, windowName, keypressCallback = None):
self.keypressCallback = keypressCallback
self._windowName = windowName
self._isWindowCreated = False
@property
def isWindowCreated(self):
return self._isWindowCreated
def createWindow(self):
cv2.namedWindow(self._windowName)
self._isWindowCreated = True
def show(self, frame):
cv2.imsmhow(self._windowName, frame)
def destroyWindow(self):
cv2.destroyWindow(self._windowName)
self._isWindowCreated = False
def processEvents(self):
keycode = cv2.waitKey(1)
if self.keypressCallback is not None and keycode != -1:
self.keypressCallback(keycode)
class Cameo(object):
def __init__(self):
self._windowManager = WindowManager('Cameo', self.onKeypress)
self._captureManager = CaptureManager(cv2.VideoCapture(0), self._windowManager, True)
#Defining the run method:
def run(self):
self._windowManager.createWindow()
while self._windowManager.isWindowCreated:
self._captureManager.enterFrame()
frame = self._captureManager.frame
if frame is not None:
self._captureManager.exitFrame()
self._windowManager.processEvents()
#Define the onKeypress method:
def onKeypress(self, keycode):
if keycode == 32:
self._captureManager.writeImage('screenshot.png')
elif keycode == 9:
if not self._captureManager.isWritingVideo:
self._captureManager.startWritingVideo('screencast.avi')
else:
self._captureManager.stopWritingVideo()
elif keycode == 27:
self._windowManager.destroyWindow()
#Adding a main block that instatiates and runs cameo
if __name__=="__main__":
Cameo().run()
我正在尝试 运行 我的代码,但我一直收到属性错误,即使我调用的属性被定义为 类 属性的一部分。将不胜感激。
这是一个简单的缩进错误。
您的所有 WindowManager
属性都在 内部 您的 __init__()
函数
中定义
(因此它们对您的程序的其余部分不可见)
这是两个代码块:
class WindowManager(object):
def __init__(self, windowName, keypressCallback = None):
self.keypressCallback = keypressCallback
self._windowName = windowName
self._isWindowCreated = False
@property
def isWindowCreated(self):
return self._isWindowCreated
def createWindow(self):
cv2.namedWindow(self._windowName)
self._isWindowCreated = True
def show(self, frame):
cv2.imsmhow(self._windowName, frame)
def destroyWindow(self):
cv2.destroyWindow(self._windowName)
self._isWindowCreated = False
def processEvents(self):
keycode = cv2.waitKey(1)
if self.keypressCallback is not None and keycode != -1:
self.keypressCallback(keycode)
class Cameo(object):
def __init__(self):
self._windowManager = WindowManager('Cameo', self.onKeypress)
self._captureManager = CaptureManager(cv2.VideoCapture(0), self._windowManager, True)
#Defining the run method:
def run(self):
self._windowManager.createWindow()
while self._windowManager.isWindowCreated:
self._captureManager.enterFrame()
frame = self._captureManager.frame
if frame is not None:
self._captureManager.exitFrame()
self._windowManager.processEvents()
#Define the onKeypress method:
def onKeypress(self, keycode):
if keycode == 32:
self._captureManager.writeImage('screenshot.png')
elif keycode == 9:
if not self._captureManager.isWritingVideo:
self._captureManager.startWritingVideo('screencast.avi')
else:
self._captureManager.stopWritingVideo()
elif keycode == 27:
self._windowManager.destroyWindow()
#Adding a main block that instatiates and runs cameo
if __name__=="__main__":
Cameo().run()
我正在尝试 运行 我的代码,但我一直收到属性错误,即使我调用的属性被定义为 类 属性的一部分。将不胜感激。
这是一个简单的缩进错误。
您的所有 WindowManager
属性都在 内部 您的 __init__()
函数
(因此它们对您的程序的其余部分不可见)