0

我有以下代码:

# -*- coding: utf-8-*-
import sys, convBB
from PyQt4 import QtGui, QtCore


class Window(QtGui.QWidget):
    def __init__(self):
        QtGui.QWidget.__init__(self)
        layout = QtGui.QVBoxLayout(self)
        self.resize(300,300)
        self.setWindowTitle('Convert_BB_test')
        self.setWindowIcon(QtGui.QIcon('icon.png'))

        self.buttonSelect = QtGui.QPushButton('Select Files', self)
        layout.addWidget(self.buttonSelect)
        self.buttonSelect.clicked.connect(self.handleButton)

        self.buttonConvert = QtGui.QPushButton('Convert', self)
        layout.addWidget(self.buttonConvert)
        self.buttonConvert.clicked.connect(self.convBB.convert(self.handleButton()))

    def handleButton(self):
        title = self.buttonSelect.text()
        file_list = QtGui.QFileDialog.getOpenFileNames(self, title)
        for path in file_list:
            print (path)
        #convBB.convert(list)
        return file_list

#if __name__ == '__main__':


app = QtGui.QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())

我从函数接收文件列表,handleButton并希望在此列表中使用函数convBB.convert(list)(来自 my ):convBB.py

self.buttonConvert.clicked.connect(self.convBB.convert(self.handleButton()))

并且有:

AttributeError: 'Window' object has no attribute 'convBB'

如何使用选择按钮选择文件,然后使用转换按钮进行转换?

4

1 回答 1

0

既然你想listbuttonCovertthen处理

  1. 将行添加self.fileList = []__init__Window
  2. 在返回之前self.fileList = file_list在方法内添加行handleButton
  3. 使用self.buttonConvert.clicked.connect(lambda: convBB.convert(self.fileList))而不是self.buttonConvert.clicked.connect(self.convBB.convert(self.handleButton()))
于 2013-09-20T05:09:53.720 回答