0
为什么这个脚本一启动就打开文件?没有节目显示。PyQt从头开始运行插槽
按下按钮时应打开文件。
如果我删除widget.connect
,那么一切正常。但按钮不起作用。
import sys
import os
from PyQt4 import QtGui, QtCore
# open file with os default program
def openFile(file):
if sys.platform == 'linux2':
subprocess.call(["xdg-open", file])
else:
os.startfile(file)
# pyQt
app = QtGui.QApplication(sys.argv)
widget = QtGui.QWidget()
button = QtGui.QPushButton('open', widget)
widget.connect(button, QtCore.SIGNAL('clicked()'), openFile('C:\file.txt'))
widget.show()
sys.exit(app.exec_())
这是什么问题widget.connect
?