如何在主函数中显示这两个界面: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)
时间: 2023-06-16 10:03:04 浏览: 127
在主函数中,你需要创建两个对象,一个是`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_())`来保证程序正常退出。
阅读全文