Python 如何在 Windows 上 pip 或 easy_install tkinter

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20044559/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 19:22:00  来源:igfitidea点击:

How to pip or easy_install tkinter on Windows

pythonpython-2.7tkinterpipeasy-install

提问by Dirk Calloway

My Idle is throwing errors that and says tkintercan't be imported.

我的空闲正在抛出错误,并说tkinter无法导入。

Is there a simple way to install tkintervia pipor easy_install?

有没有一种简单的方法可以tkinter通过pip或安装easy_install

There seem to be a lot of package names flying around for this...

似乎有很多包名称为此而飞来飞去......

This and other assorted variations with tkinter-pypyaren't working.

这个和其他各种变体tkinter-pypy都不起作用。

pip install python-tk

I'm on Windows with Python 2.7 and can't apt-get.

我在使用 Python 2.7 的 Windows 上,不能apt-get

Thanks.

谢谢。

采纳答案by LotusUNSW

Well I can see two solutions here:

好吧,我可以在这里看到两个解决方案:

1) Follow the Docs-Tkinter install for Python(for Windows):

1) 按照PythonDocs-Tkinter 安装适用于 Windows):

Tkinter (and, since Python 3.1, ttk) are included with all standard Python distributions. It is important that you use a version of Python supporting Tk 8.5 or greater, and ttk. We recommend installing the "ActivePython" distribution from ActiveState, which includes everything you'll need.

Tkinter(以及自 Python 3.1 起,ttk)包含在所有标准 Python 发行版中。使用支持 Tk 8.5 或更高版本的 Python 版本以及 ttk 非常重要。我们建议从 ActiveState 安装“ActivePython”发行版,其中包括您需要的一切。

In your web browser, go to Activestate.com, and follow along the links to download the Community Edition of ActivePython for Windows. Make sure you're downloading a 3.1 or newer version, not a 2.x version.

在您的 Web 浏览器中,转到Activestate.com,然后按照链接下载适用于 Windows 的 ActivePython 社区版。确保您下载的是 3.1 或更新版本,而不是 2.x 版本。

Run the installer, and follow along. You'll end up with a fresh install of ActivePython, located in, e.g. C:\python32. From a Windows command prompt, or the Start Menu's "Run..." command, you should then be able to run a Python shell via:

运行安装程序,然后继续。您最终将获得全新安装的 ActivePython,位于例如C:\python32. 从 Windows 命令提示符或开始菜单的“运行...”命令,您应该能够通过以下方式运行 Python shell:

% C:\python32\python

This should give you the Python command prompt. From the prompt, enter these two commands:

这应该为您提供 Python 命令提示符。在提示符下,输入以下两个命令:

>>> import tkinter
>>> tkinter._test()

This should pop up a small window; the first line at the top of the window should say "This is Tcl/Tk version 8.5"; make sure it is not 8.4!

这应该会弹出一个小窗口;窗口顶部的第一行应该说“这是 Tcl/Tk 8.5 版”;确保它不是 8.4!

2) Uninstall 64-bit Python and install 32 bit Python.

2) 卸载 64 位 Python 并安装 32 位 Python。

回答by IcyFlame

The Tkinter library is built-in with every Python installation. And since you are on Windows, I believe you installed Python through the binaries on their website?

每个 Python 安装都内置了 Tkinter 库。既然你在 Windows 上,我相信你是通过他们网站上的二进制文件安装的?

If so, Then most probably you are typing the command wrong. It should be:

如果是这样,那么很可能您输入的命令有误。它应该是:

import Tkinter as tk

Note the capital T at the beginning of Tkinter.

注意 Tkinter 开头的大写 T。

For Python 3,

对于 Python 3,

import tkinter as tk

回答by keneth

if your using python 3.4.1 just write this line from tkinter import *this will put everything in the module into the default namespace of your program. in fact instead of referring to say a button like tkinter.Buttonyou just type Button

如果您使用 python 3.4.1 只写这一行,from tkinter import *这会将模块中的所有内容放入程序的默认命名空间中。事实上,而不是指说一个按钮,就像tkinter.Button你只是输入Button

回答by Keith

If you are using virtualenv, it is fine to install tkinter using sudo apt-get install python-tk(python2), sudo apt-get install python3-tk(python3), and and it will work fine in the virtual environment

如果您使用的是 virtualenv,则可以使用sudo apt-get install python-tk(python2)、sudo apt-get install python3-tk(python3)安装tkinter,并且在虚拟环境中也能正常工作

回答by sanchez_30

I had the similar problem with Win-8 and python-3.4 32 bit , I got it resolved by downloading same version from python.org .

我在 Win-8 和 python-3.4 32 位上遇到了类似的问题,我通过从 python.org 下载相同版本解决了这个问题。

Next step will be to hit the repair button and Install the Tk/tkinter Package or Just hit the repair. Now should get Python34/Lib/tkinter Module present. The import tkinter should work ..

下一步将是点击修复按钮并安装 Tk/tkinter 包或点击修复。现在应该得到 Python34/Lib/tkinter 模块。导入 tkinter 应该可以工作..

回答by javac

I solved the same problem using these two commands 100%

我使用这两个命令 100% 解决了同样的问题

sudo yum -y update
sudo yum -y install python36u-tkinter

回答by cn123h

When you install python for Windows, use the standard option or install everything it asks. I got the error because I deselected tcl.

当您为 Windows 安装 python 时,请使用标准选项或安装它要求的所有内容。我收到错误是因为我取消了 tcl。

回答by vinothbalan64 balan

In python Tkinter was default package ,repairat the time we can select the Tcl/Tk , in c directory the tkinter stored in C:\Python27\DLLs_tkinter.pyd on that place , reinstall otherwise directly put the (_tkinter.pyd)file into DLLsenter image description here

在python中Tkinter是默认包,修复的时候我们可以选择Tcl/Tk,在c目录下tkinter存放在C:\Python27\DLLs_tkinter.pyd那个地方,重新安装否则直接把(_tkinter.pyd)文件放入DLL在此处输入图像描述

回答by jabberwocky

I'm posting as the top answer requotes the documentation which I didn't find useful.

我发布的最佳答案重新引用了我认为没有用的文档。

tkinter comes packaged with python install on windows IFF you select it during the install window.

tkinter 在 Windows IFF 上与 python install 打包在一起,您在安装窗口中选择它。

The solution is to repair the installation (via uninstall GUI is fine), and select to install tk this time. You may need to point at or redownload the binary in this process. Downloading directly from activestate did not work for me.

解决办法是修复安装(通过卸载GUI也可以),这次选择安装tk。在此过程中,您可能需要指向或重新下载二进制文件。直接从 activestate 下载对我不起作用。

This is a common problem people have on windows as it's easy to not want to install TCL/TK if you don't know what it is, but Matplotlib etc require it.

这是人们在 Windows 上遇到的一个常见问题,因为如果您不知道它是什么,很容易不想安装 TCL/TK,但是 Matplotlib 等需要它。

回答by Simon

When installing make sure that under Tcl/Tkyou select Will be installed on hard drive. If it is installing with a cross at the left then Tkinter will not be installed.

安装时请确保在Tcl/Tk您选择下Will be installed on hard drive。如果它在左侧安装一个十字,则不会安装 Tkinter。

enter image description here

在此处输入图片说明

The same goes for Python 3:

Python 3 也是如此:

enter image description here

在此处输入图片说明