【问题标题】:Better looking Tkinter File Dialogs for Python 2.7用于 Python 2.7 的更好看的 Tkinter 文件对话框
【发布时间】:2021-10-02 03:28:50
【问题描述】:

在我的应用程序中,用户需要浏览文件。但是,来自tkFileDialogaskdirectory 不太适合使用和浏览文件,因为它有些过时了。 它看起来像这样:

我想要实现的应该类似于“默认”窗口浏览对话框。像这样:

(来源https://www.pythontutorial.net/tkinter/tkinter-open-file-dialog/

我不确定(因为我找不到证据),但我记得有人告诉我它看起来像这样,因为我使用的是 Python 2.7 而不是 3+。 真的吗?是否存在替代方案?

【问题讨论】:

  • 我认为没有。它不存在
  • 您使用2.7 有什么特别的原因吗?还有一种选择是自己做一个
  • @Matiiss 我现在没有太多选择,因为这是一个大型合作项目的一部分。我们确实计划在未来的某个地方迁移到 python 3.8。
  • @RoyiLevy 好吧,其实我刚才想到了一个选项,你要不要安装一个更新版本的python Python 3.8 或者,去tkinter模块复制文件对话框的源代码,然后将其调整为Python 2.7 需要?
  • @Matiiss 我将如何处理这个问题?从来没有做过那样的事。是否有可能只“取出”那部分?

标签: python-2.7 tkinter


【解决方案1】:

您可以尝试使用askopenfilename()。它显示标准的打开文件对话框。

例如:

from tkinter import *
from tkinter import filedialog as fd

root = Tk()

root.title("Button to open files")
root.geometry("500x500")

def openfd(*args):
    askk = askopenfilename()

btn = Button(root, text="Click to open file", command=openfd)
btn.place(x=200, y=200)
root.mainloop()

您可以在https://www.pythontutorial.net/tkinter/tkinter-open-file-dialog/ 阅读更多相关信息。

【讨论】:

  • 确实看起来更好,虽然我需要用户选择一个文件夹而不是一个特定的文件。此外,给定的示例在我需要的 Python 2.7 中不起作用。
  • 哦,对不起...我不知道它在 Python 2.7 中不起作用。
猜你喜欢
  • 2011-04-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-19
  • 1970-01-01
相关资源
最近更新 更多