从一个函数获取变量的值并将其用于另一个函数-Spyder IDE

时间:2019-03-14 09:11:24

标签: python-3.x python-requests pyqt5 spyder

我是新来的。我希望你能回答我的问题。我的问题是如何从我的print_location(self)函数获取变量的值,并将其用于将要创建的另一个函数。我想在其他功能上使用fileLocation。我目前正在使用spyder和pyqt5设计器。这是我的代码

import sys
from PyQt5.QtGui import QPixmap
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtWidgets import QApplication, QDialog, QFileDialog
from PyQt5.uic import loadUi


class Life2Coding(QDialog):
    def __init__(self):
        super(Life2Coding, self).__init__()
        loadUi('sampleui.ui', self)
        self.setWindowTitle('Sample UI')
        self.pushButton.clicked.connect(self.print_location)

    @pyqtSlot()
    def print_location(self):
        fileLocation = QFileDialog.getOpenFileName(self)
        self.lineEdit.setText(str(fileLocation[0]))
        self.label.setPixmap(QPixmap(str(fileLocation[0])))
        self.label.setScaledContents(True)



app = QApplication(sys.argv)
widget = Life2Coding()
widget.show()
sys.exit(app.exec_())

如何从函数print_location获取fileLocation的值?

0 个答案:

没有答案