开发者

Open file with pyQt

开发者 https://www.devze.com 2023-03-06 14:45 出处:网络
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).

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).

Is it possible in 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?

0

精彩评论

暂无评论...
验证码 换一张
取 消