Python 3中Tkinter的文件对话框?

问题描述:

我想从对话框中选择一个文件。 这里是我需要的代码,但是当我运行它:

I want to select a file from a dialog box. Here is code that does all I need, but when I run it:

ImportError:没有名为'tkMessageBox'的模块

如何使这个例子与Python 3一起使用?

How can I make this example work with Python 3?

Tkinter 已在Python 3中重命名为 tkinter ,以及与其相关的其他模块。以下是更改名称:

The package Tkinter has been renamed to tkinter in Python 3, as well as other modules related to it. Here are the name changes:


  • Tkinter tkinter

  • tkMessageBox tkinter.messagebox / li>
  • tkColorChooser tkinter.colorchooser

  • tkFileDialog tkinter.filedialog

  • tkCommonDialog tkinter.commondialog

  • tkSimpleDialog tkinter.simpledialog

  • tkFont →$ code> tkinter .font

  • Tkdnd tkinter.dnd

  • ScrolledText tkinter.scrolledtext

  • Tix tkinter.tix

  • ttk tkinter.ttk

  • Tkintertkinter
  • tkMessageBoxtkinter.messagebox
  • tkColorChoosertkinter.colorchooser
  • tkFileDialogtkinter.filedialog
  • tkCommonDialogtkinter.commondialog
  • tkSimpleDialogtkinter.simpledialog
  • tkFonttkinter.font
  • Tkdndtkinter.dnd
  • ScrolledTexttkinter.scrolledtext
  • Tixtkinter.tix
  • ttktkinter.ttk

我建议您学习如何使用 dir 命令。如果您在Windows下,请配置Python以使用 readline 模块获取自动完成在模块中列出可用的类更容易。

I advise you to learn how to dynamically browse the modules with the dir command. If you are under windows, configure Python to use readline module to get auto-completion and make it much easier to list available classes in a module.