问题描述
我正在制作一个小应用程序,它将帮助我跟踪项目和项目的截止日期.我想添加的一件事是能够在文件资源管理器中打开主项目文件夹.我通过将文本设置为
I am making a small application that will help me keep track of projects and the due dates of the projects. One of the things I would like to add is the ability to open the main project folder in the file explorer. I have the QLabel link working by setting the text to
(label.setText('<a href='+ProjectFolder+'>Open Project Folder</a>')
我有
label.setOpenExternalLinks(True)
但是当我点击它时什么也没有发生,我在终端窗口中收到错误消息.他们都像
But when I click on it nothing happens and I'm getting errors in the terminal window. They are all something like
ShellExecute 'z:%5C16904' 失败(错误 2)
我假设这是因为 \
和链接中的空格,但我不确定如何修复它们.我试过 '\\' 但似乎没有帮助.任何建议都会非常有用.谢谢你的时间
I'm assuming this is because of \
and spaces that are in the link, but I'm not sure how to fix them. I have tried '\\' but doesn't seem to help. Any advice would be much apricated. Thank you for your time
推荐答案
首先使用正斜杠/
.
您可以尝试将 %20
C:/Program%20Files"
用于空格,但它对我不起作用,即使我看到正确的空格而不是 %5C 中控制台输出日志.如果您确实需要在文件夹中使用空格,请检查此
You can try to use %20
C:/Program%20Files"
for whitespaces but it didn't work for me even though I see proper whitespace instead of %5C
inconsole output log. If you really need to use whitespaces in folders check this
QLabel("<a href={}>Open Project Folder</a>".format("`C:/Progra~1/needed"`))
这篇关于PYQT QLabel 链接以打开计算机上的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!