from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QFileDialog
class Ui_linux_installer(object):
def setupUi(self, linux_installer):
linux_installer.setObjectName("linux_installer")
linux_installer.resize(552, 163)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(linux_installer.sizePolicy().hasHeightForWidth())
linux_installer.setSizePolicy(sizePolicy)
linux_installer.setMinimumSize(QtCore.QSize(552, 163))
linux_installer.setMaximumSize(QtCore.QSize(552, 163))
self.centralwidget = QtWidgets.QWidget(linux_installer)
self.centralwidget.setObjectName("centralwidget")
self.button_install = QtWidgets.QPushButton(self.centralwidget)
self.button_install.setGeometry(QtCore.QRect(420, 120, 121, 31))
self.button_install.setObjectName("button_install")
self.line_path_file = QtWidgets.QLineEdit(self.centralwidget)
self.line_path_file.setGeometry(QtCore.QRect(10, 80, 501, 31))
self.line_path_file.setObjectName("line_path_file")
self.button_dialog = QtWidgets.QToolButton(self.centralwidget)
self.button_dialog.setGeometry(QtCore.QRect(512, 80, 31, 31))
self.button_dialog.setObjectName("button_dialog")
self.label_info = QtWidgets.QLabel(self.centralwidget)
self.label_info.setGeometry(QtCore.QRect(10, 10, 531, 41))
self.label_info.setWordWrap(True)
self.label_info.setObjectName("label_info")
self.label_file = QtWidgets.QLabel(self.centralwidget)
self.label_file.setGeometry(QtCore.QRect(10, 60, 521, 17))
self.label_file.setObjectName("label_file")
self.button_close = QtWidgets.QPushButton(self.centralwidget)
self.button_close.setGeometry(QtCore.QRect(290, 120, 121, 31))
self.button_close.setObjectName("button_close")
linux_installer.setCentralWidget(self.centralwidget)
self.retranslateUi(linux_installer)
QtCore.QMetaObject.connectSlotsByName(linux_installer)
def retranslateUi(self, linux_installer):
_translate = QtCore.QCoreApplication.translate
linux_installer.setWindowTitle(_translate("linux_installer", "Linux Installer"))
self.button_install.setText(_translate("linux_installer", "Установить"))
#self.line_path_file.setText(_translate("linux_installer", ""))
self.button_dialog.setText(_translate("linux_installer", "..."))
#self.label_info.setText(_translate("linux_installer", " "))
self.label_file.setText(_translate("linux_installer", "Файл для установки:"))
self.button_close.setText(_translate("linux_installer", "Закрыть"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
linux_installer = QtWidgets.QMainWindow()
ui = Ui_linux_installer()
ui.setupUi(linux_installer)
linux_installer.show()
# Кнопка закрывает окно
close = linux_installer.close
ui.button_close.clicked.connect( close )
# тут не работает! Функция открытия файла:
def showDialog(self):
fname = QFileDialog.getOpenFileName(self, 'Open file', '/home')[0]
print(fname)
# Вызов функции showDialog
ui.button_dialog.clicked.connect( showDialog )
sys.exit(app.exec_())
При нажатии button_dialog такая ошибка:
Traceback (most recent call last):
File "main.py", line 68, in showDialog
fname = QFileDialog.getOpenFileName(self, 'Open file', '/home')[0]
TypeError: getOpenFileName(parent: QWidget = None, caption: str = '', directory: str = '', filter: str = '', initialFilter: str = '', options: Union[QFileDialog.Options, QFileDialog.Option] = 0): argument 1 has unexpected type 'bool'