self.lblRedLight.setPixmap(red_light_pixmap) AttributeError: 'Ui_MainWindow' object has no attribute 'lblRedLight'
时间: 2023-07-14 18:09:40 浏览: 50
根据您提供的错误信息,看起来是由于在 `Ui_MainWindow` 对象中没有名为 `lblRedLight` 的属性导致的错误。
请确保您的 `Ui_MainWindow` 类或对象中存在一个名为 `lblRedLight` 的 QLabel,以便在代码中设置红灯的显示。您可以检查您的界面设计文件(通常是一个以 `.ui` 结尾的文件),或者查看您的代码中是否正确初始化了 `lblRedLight`。
如果您确定 `lblRedLight` 已经存在,请确保它在 `Ui_MainWindow` 类的正确位置声明,并检查是否正确设置了它的对象名称。
如果问题仍然存在,请提供更多关于您的代码和界面设计的细节,以便我能够更好地帮助您解决问题。
相关问题
self.label.setPixmap(pixmap) # 在标签上显示图片 AttributeError: 'MainWindow' object has no attribute 'label'
这是一个Python错误,意味着在MainWindow类中没有名为"label"的属性或方法。通常,这种错误发生在调用一个类中不存在的属性或方法时。
在这个例子中,可能是因为MainWindow类中没有一个名为"label"的标签控件,或者该标签控件的名称不是"label"。要解决这个问题,可以检查MainWindow类中是否存在一个名为"label"的标签控件,并确保在调用`self.label.setPixmap(pixmap)`之前先创建该控件。如果没有该控件,可以在MainWindow类中添加一个标签控件,并将其名称设置为"label"。
如何在主函数中显示这两个界面:class Faceshow(QMainWindow, Ui_MainWindow): def __init__(self, parent=None): super(Faceshow, self).__init__(parent) self.setupUi(self) self.main_button.clicked.connect(start) self.main_exit.clicked.connect(self.quit) def quit(self): self.close() class RESUshow(QWidget, Ui_Form): def __int__(self, parent=None): super(RESUshow, self).__init__(parent) self.setupUi(self) img1, img2, text1, text2 = start() pixmap1 = QPixmap.fromImage(img1) pixmap2 = QPixmap.fromImage(img2) self.label_img1.setPixmap(pixmap1) self.label_img2.setPixmap(pixmap2) self.label_psnr.setText(text1) self.label_ssim.setText(text2)
在主函数中,你需要创建两个对象,一个是`Faceshow`,另一个是`RESUshow`。然后,当`Faceshow`的`main_button`被点击时,调用`start`函数并显示`RESUshow`界面。
以下是示例代码:
```
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow
from PyQt5.QtGui import QPixmap
from faceshow import Faceshow
from resushow import RESUshow
def start():
# your code here
return img1, img2, text1, text2
class Main(QMainWindow):
def __init__(self):
super(Main, self).__init__()
self.faceshow = Faceshow()
self.resushow = RESUshow()
self.faceshow.main_button.clicked.connect(self.show_resushow)
self.faceshow.main_exit.clicked.connect(self.quit)
def show_resushow(self):
img1, img2, text1, text2 = start()
pixmap1 = QPixmap.fromImage(img1)
pixmap2 = QPixmap.fromImage(img2)
self.resushow.label_img1.setPixmap(pixmap1)
self.resushow.label_img2.setPixmap(pixmap2)
self.resushow.label_psnr.setText(text1)
self.resushow.label_ssim.setText(text2)
self.resushow.show()
def quit(self):
self.close()
if __name__ == '__main__':
app = QApplication(sys.argv)
main = Main()
main.faceshow.show()
sys.exit(app.exec_())
```
在这个例子中,`Main`类继承自`QMainWindow`,并包含了两个对象:`Faceshow`和`RESUshow`。在`show_resushow`函数中,我们调用`start`函数并将结果显示在`RESUshow`界面中。
在`if __name__ == '__main__':`中,我们创建了`QApplication`对象和`Main`对象,并显示`Faceshow`界面。最后,我们调用`sys.exit(app.exec_())`来保证程序正常退出。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)