class RESUshow(QWidget, Ui_Form): def init(self, img1, img2, text1, text2, 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)如何将上述代码移植到下列代码中:import sys from repair import Ui_MainWindow from PyQt5.QtWidgets import QApplication, QMainWindow from interface import start 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() if name == 'main': hxz = QApplication(sys.argv) ui = Faceshow() ui.show() sys.exit((hxz.exec_())) 其中RESUshow窗口是QtWidgets,要求Faceshow修复完成的同时将四个参数传入RESUshow并自动弹出展示
时间: 2023-06-14 07:04:58 浏览: 164
2个QWidget相互切换显示.zip
你可以将RESUshow窗口的代码复制到Faceshow的init函数中,并在start函数中创建RESUshow实例,然后传递参数并展示。
代码如下:
```python
import sys
from repair import Ui_MainWindow
from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget
from PyQt5.QtGui import QPixmap
from interface import start
class RESUshow(QWidget, Ui_Form):
def __init__(self, img1, img2, text1, text2, parent=None):
super(RESUshow, self).__init__(parent)
self.setupUi(self)
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)
class Faceshow(QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
super(Faceshow, self).__init__(parent)
self.setupUi(self)
self.main_button.clicked.connect(self.show_result)
self.main_exit.clicked.connect(self.quit)
def show_result(self):
img1, img2, text1, text2 = start()
self.resu = RESUshow(img1, img2, text1, text2)
self.resu.show()
def quit(self):
self.close()
if __name__ == '__main__':
app = QApplication(sys.argv)
ui = Faceshow()
ui.show()
sys.exit(app.exec_())
```
在这个修改后的代码中,当用户点击main_button时,会调用show_result函数,在函数中调用start函数获取四个参数,然后创建RESUshow实例并传递这四个参数,最后展示RESUshow窗口。
阅读全文