简体   繁体   English

用pyQt打开文件

[英]Open file with pyQt

There is a button. 有一个按钮。
When it is clicked, file C:\\file.txt should be opened with default text editor (as if it is double clicked). 单击它时,应使用默认文本编辑器打开文件C:\\file.txt (就像双击一样)。
Is it possible in pyQt? 在pyQt中有可能吗? Button is pressed -> file is opened. 按下按钮 - >文件打开。
All I can google is just dialogs, but I don't need them. 所有我可以谷歌只是对话,但我不需要它们。

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

How it can be done? 怎么做?

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

And edit your 2nd line to: 并编辑您的第二行:

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

Code for opening file copied from How to open a file with the standard application? 如何使用标准应用程序打开文件复制打开文件的代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM