在pyqt中将变量从一页传递到另一页

问题描述 投票:0回答:1

我正在尝试在以下代码中将image_name变量从第一页传递到第二页

def image_button_clicked(self):
        #filter = "Images (*.png)"
        included_extensions = ['jpg','jpeg', 'bmp', 'png', 'gif']

        image_name,_ = QFileDialog.getOpenFileName(None, "Select an image", "", "Image Files (*.png *.jpg *.bmp)")

def FirstPage(self):

        select_imageLabel = QLabel("Image")
        select_imageEdit = QLineEdit()
        select_image_button=QPushButton("Browse")
        select_image_button.clicked.connect(self.image_button_clicked)

def SecondPage(self):

        pixmap = QPixmap(image_name)
        smaller_pixmap = pixmap.scaled(220,220, Qt.KeepAspectRatio, Qt.FastTransformation)
        labelImage.setPixmap(smaller_pixmap)

所以,我试图从第一页读取image_name并在第二页中打印图像,但是什么也没显示。

python pyqt pyqt5 pyqt4
1个回答
0
投票

image_name之前将global image_name定义为image_name,_ = QFileDialog.getOpenFileName(None, "Select an image", "", "Image Files (*.png *.jpg *.bmp)")

© www.soinside.com 2019 - 2024. All rights reserved.