程序运行提示AttributeError: 'MyWindow' object has no attribute 'saved_color_photos',优化程序class MyWindow(QWidget): def __init__(self): super().__init__() self.thread_list = [] self.image_thread = None self.init_ui() def init_ui(self): self.ui = uic.loadUi("C:/Users/wyt/Desktop/D405界面/intelrealsense1.ui") def open(self): self.profile = self.pipeline.start(self.config) self.is_camera_opened = True self.label.setText('相机已打开') self.label.setStyleSheet('color:green') self.open_btn.setEnabled(False) self.close_btn.setEnabled(True) self.image_thread = ImageThread(self.pipeline, self.color_label, self.depth_label, self.interval, self.color_photo_dir, self.depth_photo_dir, self._dgl) self.image_thread.saved_color_photos_signal.connect(self.update_saved_color_photos_label) self.image_thread.saved_depth_photos_signal.connect(self.update_saved_depth_photos_label) self.image_thread.start() def close(self): self.image_thread.stop() self.pipeline.stop() self.is_camera_opened = False self.label.setText('相机未打开') self.label.setStyleSheet('color:red') self.open_btn.setEnabled(True) self.close_btn.setEnabled(False) print("已保存color_image的数量是:%d" % self.saved_color_photos) print("已保存depth_image的数量是:%d" % self.saved_depth_photos) self.hide() # 将窗口隐藏,而非退出程序
时间: 2024-01-30 15:04:04 浏览: 130
【Python】AttributeError: ‘AutoSchema’ object has no attribute ‘get_link’
5星 · 资源好评率100%
根据错误提示,似乎你在某个地方使用了 `self.saved_color_photos`,但是 `MyWindow` 类中并没有定义这个属性,因此出现了 `AttributeError`。你需要在 `__init__()` 方法中定义 `self.saved_color_photos` 和 `self.saved_depth_photos` 两个属性,例如:
```python
class MyWindow(QWidget):
def __init__(self):
super().__init__()
self.thread_list = []
self.image_thread = None
self.saved_color_photos = 0 # 定义 saved_color_photos 属性
self.saved_depth_photos = 0 # 定义 saved_depth_photos 属性
self.init_ui()
# 省略其他方法
```
这样就可以避免出现上述错误了。
阅读全文