我是pyqt的新手,目前正在尝试让文件对话框功能正常工作。它可以打印类和函数内部的文件名,但不能将文件名保存到函数外部的变量中
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QInputDialog, QLineEdit, QFileDialog
from PyQt5.QtGui import QIcon
class open_file(QWidget):
global file_name
def __init__(self):
super().__init__()
self.title = 'Select Image'
self.left = 10
self.top = 10
self.width = 640
self.height = 480
self.initUI()
def initUI(self):
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
self.openFileNamesDialog()
self.show()
def openFileNamesDialog(self):
options = QFileDialog.Options()
options |= QFileDialog.DontUseNativeDialog
files, _ = QFileDialog.getOpenFileNames(self, "QFileDialog.getOpenFileNames()", "",
"Images (*.png *.jpg)", options=options)
return files
names = ex.openFileNamesDialog()
print(names)
我希望在选择文件后打印文件名,但什么都不会打印
试试看:
相关问题 更多 >
编程相关推荐