我正在尝试为我在这里的一些人的帮助下编写的一个小程序制作一个 GUI,无论如何,我在 PyQt 中制作了 GUI,它看起来不错。我添加了一个名为 dirButton 的按钮,上面写着“选择目录”
self.dirButton = QtGui.QPushButton(self.buttonWidget)
self.dirButton.setGeometry(QtCore.QRect(0, 0, 91, 61))
self.dirButton.setObjectName(_fromUtf8("dirButton"))
self.dirButton.clicked.connect(self.browse)
在底行中,当我单击它时,我将其称为 self.browse,即:
def browse(self):
filename = QtGui.QFileDialog.getOpenFileName(self, 'Open File', '.')
fname = open(filename)
data = fname.read()
self.textEdit.setText(data)
fname.close()
但是,这是我得到的错误:
Traceback (most recent call last):
File "C:\Users\Kevin\Desktop\python-tumblr-0.1\antearaGUI.py", line 88, in browse
filename = QtGui.QFileDialog.getOpenFileName(self, 'Open File', '.')
TypeError: QFileDialog.getOpenFileName(QWidget parent=None, QString caption=QString(), QString directory=QString(), QString filter=QString(), QString selectedFilter=None, QFileDialog.Options options=0): argument 1 has unexpected type 'Ui_mainWindow'
因此,ui_mainWindow 是存储我的所有 GUI 按钮和 GUI 本身的类。
class Ui_mainWindow(object):
我不明白为什么我会收到错误,有人有任何想法吗?
这是整个 GUI 的 Pastebin 链接:http://pastebin.com/BWCcXxUW http://pastebin.com/BWCcXxUW