用pyQt打开文件

时间:2011-05-18 13:40:54

标签: python pyqt

有一个按钮 单击它时,应使用默认文本编辑器打开文件C:\file.txt(就像双击一样)。
在pyQt中有可能吗?按下按钮 - >文件已打开。
我只能用谷歌对话,但我不需要它们。

file = 'C:\file.txt'
widget.connect(button, QtCore.SIGNAL('clicked()'), ????)

怎么做?

1 个答案:

答案 0 :(得分:2)

def openFile(file):
    if sys.platform == 'linux2':
        subprocess.call(["xdg-open", file])
    else:
        os.startfile(file)

将第二行编辑为:

widget.connect(button, QtCore.SIGNAL('clicked()'), openFile(file))

打开从How to open a file with the standard application?

复制的文件的代码