Qt中实例化出现AttributeError: 'Window2' object has no attribute 'show'
时间: 2023-11-18 16:04:07 浏览: 45
出现AttributeError: 'Window2' object has no attribute 'show'的原因可能是在Window2类中没有定义show()方法。可以检查一下Window2类的定义,看看是否有show()方法。如果没有,可以在类中添加show()方法,如下所示:
```python
class Window2(QtWidgets.QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Window2")
self.setGeometry(100, 100, 500, 500)
self.central_widget = QtWidgets.QWidget()
self.setCentralWidget(self.central_widget)
def show(self):
super().show()
```
在这个例子中,我们在Window2类中添加了show()方法,该方法调用了父类的show()方法,以显示窗口。如果你的问题不是由于缺少show()方法引起的,那么你需要检查你的代码,看看是否有其他错误。
相关问题
TXT转XML出现AttributeError: NoneType object has no attribute shape
TXT转XML出现AttributeError: NoneType object has no attribute shape可能是因为代码中出现了None值,而None值没有shape属性。需要检查代码中是否存在None值,并进行处理。另外,也需要检查代码中是否正确地读取了TXT文件并将其转换为XML格式。
AttributeError: type object object has no attribute find
很抱歉,引用中提到的错误信息是"AttributeError: type object ‘object’ has no attribute 'dtype’",而非"AttributeError: type object object has no attribute find"。这个错误通常是由于pandas或numpy版本问题引起的,可以尝试升级或降级这些库的版本来解决。具体的解决方法可以参考引用中提供的链接。