我已经检查了here,并且独立地尝试了代码,它工作了…但是在我的QTreeView应用程序中插入代码…它打开了以“我的文档”为焦点的浏览器用户库
我使用subprocess.Popen(r'explorer /select,"file_path"')
这是我的密码
def on_clicked(self, index):
# self.path = self.fileSystemModel.fileInfo(index).absoluteFilePath()
self.path = self.fileSystemModel.filePath(index)
print(self.path
def tabMenu(self, positon):
self.tmenu = QMenu()
self.open = self.tmenu.addAction('Open')
self.open_file_location = self.tmenu.addAction('Open File Location')
self.tmenu.addActions([self.open, self.open_file_location])
action = self.tmenu.exec_(self.temp_treeView.viewport().mapToGlobal(position))
if action == self.open:
os.startfile(self.path, 'open')
elif action == self.open_file_location:
print(self.path)
subprocess.Popen(r'explorer /select,' + self.path)
self.path = self.fileSystemModel.filePath(index)
返回带有/
的文件路径,subprocess.Popopen(r'explorer /select,"path")
无法访问该路径。.您需要将/
转换为\
才能正常工作…通过subprocess.Popen(r'explorer /select,'+"{}".format(path).replace('/', '\\'))
转换字符串相关问题 更多 >
编程相关推荐