PyQt In Blender AttributeError

When I pass the signal from QPushbutton to create one object in Blender is showing AttributeError

AttributeError: ‘Context’ object has no attribute ‘object’ on passing

#Source Code############################################
import sys
import bpy
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow
from PyQt5 import QtCore
from PyQt5 import QtGui

class Windows (QtWidgets.QMainWindow):
def init(self, parent=None):
super(Windows, self).init(parent)
self.pushButton = QtWidgets.QPushButton(self)
self.pushButton.setGeometry (QtCore.QRect(20, 10, 250, 50))
self.pushButton.setText (‘Apply’)
self.resize(300, 70)
self.pushButton.clicked.connect (self.createEmptObject)

def createEmptObject (self) :   
    bpy.ops.object.empty_add ()    
    bpy.context.object.name = 'New_Empty_Object'   

app = QtWidgets.QApplication(sys.argv)
window = Windows()
window.show()

#End############################################

#Error
Traceback (most recent call last):
File “\Text.001”, line 20, in createEmptObject
AttributeError: ‘Context’ object has no attribute ‘object’

  • How I can manage this AttributeError problem
  • I am new in Blender. Any help would be greatly appreciated!

First, why do you want to use PyQt? Blender has already a lot of widgets that are very well integrated into Blender UI.
If you want to do it anyway, Qt window is not a Blender context. It has no object, space_data, region, etc. The only thing you could do is to pass those context references when you create your Qt window.
It’s working well but you probably don’t want to do that. You told you’re new to Blender and talk about “Attribute Editor”, let Maya stuff for Maya and try to do it in the Blender way. There is two panels, on the right and on the left and it has already probably the things you’re looking for, if not, you can use Blender API to add stuff directly there.

With respect, I disagree with limiting GUI inputs into Blender to exclusively use the Blender UI API. The primary problem with that limitation is that the Blender API only works in one individual’s idea of what an interface should be, and the fluidity of context change and multiple UI contexts is lost in a clutter of subdivided docks. While this was acceptable for Commodore Amiga users back in the glory days of the 1980s, it’s a bit of a frustration for people who could otherwise program additional add-ons to Blender using external toolkits.