简体   繁体   English

导入 tkinter:模块列表

[英]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导入tkinter不会导入一些基本且有用的模块,例如messagebox ,如下所述: tkinter.messagebox.showinfo 并不总是有效

How do I check which modules are actually imported with import tkinter and which ones can be potentially imported by importing them explicitly (eg from tkinter import messagebox )?我如何检查哪些模块实际上是使用import tkinter导入的,哪些模块可以通过显式导入(例如from tkinter import messageboxfrom tkinter import messagebox

How do I check which modules are actually imported with import tkinter?如何使用 import tkinter 检查实际导入了哪些模块?

Use this code example to check all that is imported with tkinter:使用此代码示例检查使用 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:如果您花时间阅读tkinter 文档,您将看到一个部分,内容如下:

Other modules that provide Tk support include:其他提供 Tk 支持的模块包括:

tkinter.scrolledtext Text widget with a vertical scroll bar built in. tkinter.scrolledtext 内置垂直滚动条的文本小部件。

tkinter.colorchooser Dialog to let the user choose a color. tkinter.colorchooser 对话框让用户选择颜色。

tkinter.commondialog Base class for the dialogs defined in the other modules listed here. tkinter.commondialog 此处列出的其他模块中定义的对话框的基类。

tkinter.filedialog Common dialogs to allow the user to specify a file to open or save. tkinter.filedialog 允许用户指定要打开或保存的文件的通用对话框。

tkinter.font Utilities to help work with fonts. tkinter.font 帮助处理字体的实用程序。

tkinter.messagebox Access to standard Tk dialog boxes. tkinter.messagebox 访问标准 Tk 对话框。

tkinter.simpledialog Basic dialogs and convenience functions. tkinter.simpledialog 基本对话框和便利功能。

tkinter.dnd Drag-and-drop support for tkinter. tkinter.dnd 对 tkinter 的拖放支持。

This is experimental and should become deprecated when it is replaced with the Tk DND.这是实验性的,当它被 Tk DND 取代时应该被弃用。 turtle Turtle graphics in a Tk window.海龟 Tk 窗口中的海龟图形。

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 .我认为应该在本节中列出的一个没有接缝的是ttk The ttk imports are also separate from * . ttk导入也与*分开。

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.对于ttk导入,您可以使用外观漂亮的按钮和其他小部件,它们都使用可以在代码中设置的通用样式。 It is visually nice to use but not 100% needed in the work that is done in the GUI.它在视觉上很好用,但不是 100% 需要在 GUI 中完成的工作。

this is all in the tkinter documentation so do yourself a favor and read it.这都在tkinter 文档中,所以帮自己一个忙并阅读它。 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)那里有很多有用的信息不会通过搜索 StackOverflow 获得。(好吧,也许你可以先去文档)

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.通常,您可以查看如图所示的目录;(如果您在 .py 脚本中,则需要打印()该目录。)并查看是否不包含您想要的任何组件。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM