【问题标题】:In python is there a way to use the windows explorer to create a file path which can then be returned as a string?在 python 中,有没有办法使用 Windows 资源管理器创建一个文件路径,然后可以将其作为字符串返回?
【发布时间】:2013-12-16 15:17:21
【问题描述】:

我正在制作一个程序来管理数据库,我需要一种在程序中选择文件保存位置的好方法。我想知道是否可以从我的程序中打开 windows explore,选择一个文件夹来保存文件,输入文件名并将文件路径作为字符串返回给主程序。

【问题讨论】:

    标签: python windows-explorer


    【解决方案1】:

    tkFileDialog 中查找 Tkinter 选项

    我认为您不一定需要组装一个完整的 GUI,您可以简单地调用该方法并选择一个文件夹位置,然后在您的代码中使用该选定位置。

    一个简单的例子是:

    import Tkinter, tkFileDialog
    
    root = Tkinter.Tk()
    
    x = tkFileDialog.askopenfilename() # Can pass optional arguments for this...
    
    root.destroy()
    

    【讨论】:

      猜你喜欢
      • 2013-01-30
      • 2023-01-25
      • 2019-01-29
      • 2017-07-07
      • 1970-01-01
      • 1970-01-01
      • 2012-08-07
      • 1970-01-01
      • 2022-08-18
      相关资源
      最近更新 更多