from PyQt5.QtCore import QUrl
from PyQt5.QtGui import QDesktopServices
def button_show_dir(self):
default_dir = "./report_pdf"
show_dirPath = 0
if self.dir_choose == 0:
show_dirPath = default_dir
else:
show_dirPath = self.dir_choose
url = QUrl.fromLocalFile(show_dirPath)
if url:
print("选择的文件夹路径:", show_dirPath)
else:
print("未选择文件夹")
QDesktopServices.openUrl(url)
PyQt 打开文件夹路径
最新推荐文章于 2024-01-08 19:22:30 发布
该代码片段展示了如何在PyQt5应用中使用QUrl和QDesktopServices处理用户选择的文件夹路径,当用户点击按钮时,程序会打印路径并尝试打开选定的本地文件夹。
1091

被折叠的 条评论
为什么被折叠?



