import tkinter: list of modules

3.1k views Asked by At

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)?

2

There are 2 answers

2
Mike - SMT On BEST ANSWER

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.

0
SRT HellKitty On

this is all in the tkinter documentation so do yourself a favor and read it. There is a lot of useful information in there that won't be gained from searching StackOverflow.(well, maybe you can but go to the documentation first)

in general, you can look in the directory as shown;(if you are in a .py script you will need to print() the dir.) and see if any components you want are not included.

>>> import tkinter as tk
>>> dir(tk)