pythonpython-3.xtkinterimporttkmessagebox

import tkinter: list of modules


Importing tkinter doesn't import some basic and useful modules such as messagebox, as explained here: tkinter.messagebox.showinfo doesn't always work

How do I check which modules are actually imported with import tkinter and which ones can be potentially imported by importing them explicitly (e.g. from tkinter import messagebox)?


Solution

  • How do I check which modules are actually imported with import tkinter?

    Use this code example to check all that is imported with tkinter:

    import tkinter as tk
    help(tk)
    

    You will get a large amount of data printed to the console that shows all the imports and "constants" that are imported with *.

    If you take the time to read the tkinter documentation you will see a section that says the following:

    Other modules that provide Tk support include:

    tkinter.scrolledtext Text widget with a vertical scroll bar built in.

    tkinter.colorchooser Dialog to let the user choose a color.

    tkinter.commondialog Base class for the dialogs defined in the other modules listed here.

    tkinter.filedialog Common dialogs to allow the user to specify a file to open or save.

    tkinter.font Utilities to help work with fonts.

    tkinter.messagebox Access to standard Tk dialog boxes.

    tkinter.simpledialog Basic dialogs and convenience functions.

    tkinter.dnd Drag-and-drop support for tkinter.

    This is experimental and should become deprecated when it is replaced with the Tk DND. turtle Turtle graphics in a Tk window.

    This section contains all the other commonly needed imports that do not get imported with *. One that does not seam to be listed in this section that I believe should be is ttk. The ttk imports are also separate from *.

    For ttk imports you can use fancy looking buttons and other widgets that all use a common style that can be set in the code as well. It is visually nice to use but not 100% needed in the work that is done in the GUI.