【问题标题】:How to convert this relative path to an absolute path?如何将此相对路径转换为绝对路径?
【发布时间】:2020-11-22 06:16:00
【问题描述】:

所以,这是一个 Tkinter - Python 软件,它从我提供的系统路径中获取图像,但是如何更改它,以便当其他人下载它并使用他们的文件路径时使用我认为一些 abspath 可以被使用。

img= PhotoImage(file="D:/Coding GCB/Python (Building)/ProductiveSearch/res/do1.png")

【问题讨论】:

标签: python tkinter path filepath absolute


【解决方案1】:

导入操作系统

os.path.abspath("mydir/myfile.txt")

您还可以阅读有关路径模块的更多信息来执行此操作

从路径库导入路径

【讨论】:

    【解决方案2】:
    import os
    
    os.path.abspath('<relative to script>/do1.png̈́')
    

    abspath doc

    【讨论】:

      猜你喜欢
      • 2017-08-01
      • 2011-11-07
      • 2011-05-02
      • 2015-01-24
      相关资源
      最近更新 更多