python - 如何在 macOS Sierra 上使用 tkinter 模块

标签 python macos tkinter

我正在尝试学习如何在 Python 中使用 tkinter 模块,但是当我在本地运行它时,出现以下错误:

Traceback (most recent call last):
  File "emailer", line 1, in <module>
    from tkinter import messagebox
ImportError: No module named tkinter

我尝试过 pip install tkintersudo pip install tkinter ,这会引发以下错误:

Could not find a version that satisfies the requirement tkinter (from versions: )
No matching distribution found for tkinter

最后,在终端中运行 which python 时,输出为 /usr/bin/python

最佳答案

If you are using Python from a python.org 64-bit/32-bit Python installer for Mac OS X 10.6 and later, you should only use IDLE or tkinter with an updated third-party Tcl/Tk 8.5 (not 8.6), like ActiveTcl 8.5 installed.

If you are using Mac OS X 10.6, do not use IDLE or Tkinter from the Apple-supplied Python 2.6.1 in Mac OS X 10.6. If possible, install and use a newer version of Python and of Tcl/Tk.

If you are using Mac OS X 10.7 or later, the Apple-supplied Tcl/Tk 8.5 still has serious bugs that can cause application crashes. If you wish to use IDLE or Tkinter, install and use a newer version of Python and of Tcl/Tk.

实际上你可以使用自制:

brew install tcl-tk

brew link tcl-tk --force

看看tcltk .

关于python - 如何在 macOS Sierra 上使用 tkinter 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42345189/

相关文章:

macos - 如何使用 Homebrew 软件在 mac 上安装 Solr?

macos - OSX 打开取景器并显示图像

python - 帮助 MySQL LOAD DATA INFILE

python - Django-registration user_activated信号发送两次

python - 无法在 Pepper 上的 Choregraphe 中导入 python 模块

python - 使用python计算csv特定列中的行条目数

macos - 使用节点 webkit 在 Mac OS 上单击 "x"时关闭窗口但不是应用程序

python - 如何在主循环期间更改 Tkinter 应用程序的默认字体?

python - 通过 tkinter 条目将数据从列表写入文件

python - python中的按钮数组