问题:如何在Windows上点子或easy_install tkinter

我的空闲状态抛出错误,并指出tkinter无法导入。

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

似乎有很多软件包名称在出现……

此版本以及其他各种各样的版本tkinter-pypy均无效。

pip install python-tk

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

谢谢。

My Idle is throwing errors that and says tkinter can’t be imported.

Is there a simple way to install tkinter via pip or easy_install?

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

This and other assorted variations with tkinter-pypy aren’t working.

pip install python-tk

I’m on Windows with Python 2.7 and I don’t have apt-get or other system package managers.


回答 0

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

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

所有标准的Python发行版都包含Tkinter(以及从Python 3.1开始的ttk)。使用支持Tk 8.5或更高版本以及ttk的Python版本很重要。我们建议从ActiveState安装“ ActivePython”发行版,其中包括您需要的所有内容。

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

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

% C:\python32\python

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

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

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

2)卸载64位Python,然后安装32位Python。

Well I can see two solutions here:

1) Follow the Docs-Tkinter install for Python (for 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.

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.

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:

% C:\python32\python

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

>>> 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!

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


回答 1

Tkinter库在每个Python安装中都是内置的。而且由于您使用的是Windows,我相信您是通过Python的网站上的二进制文件安装的吗?

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

import Tkinter as tk

注意Tkinter开头的大写字母T。

对于Python 3,

import tkinter as tk

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?

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.

For Python 3,

import tkinter as tk

回答 2

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

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


回答 3

在安装时,请确保Tcl/Tk选择下Will be installed on hard drive。如果安装时带有左侧的叉号,则不会安装Tkinter。

在此处输入图片说明

Python 3也是如此:

在此处输入图片说明

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

enter image description here

The same goes for Python 3:

enter image description here


回答 4

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

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


回答 5

在Linux中也有同样的问题。这解决了。(我正在使用Debian 9衍生的本生氦气)

$ sudo apt-get install python3-tk

Had the same problem in Linux. This solved it. (I’m on Debian 9 derived Bunsen Helium)

$ sudo apt-get install python3-tk


回答 6

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

如果您在安装窗口中选择了tkinter,则会在Windows IFF上将python install打包在一起。

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

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

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.

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.

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.


回答 7

在python中,Tkinter是默认软件包,您可以修复安装并选择Tcl / Tk。修理运行此命令时,应按以下方式安装DDL:在此处输入图片说明

In python, Tkinter was a default package, you can repair the installation and select Tcl/Tk. repair When you run this, DDL should be installed like so: enter image description here


回答 8

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

下一步将是点击修复按钮并安装Tk / tkinter软件包,或者只是修复。现在应该获得Python34 / Lib / tkinter模块。导入tkinter应该工作..

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 .

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 ..


回答 9

在内部cmd,运行命令pip install tk和Tkinter应该安装。

Inside cmd, run command pip install tk and Tkinter should install.


回答 10

最简单的方法:

cd C:\Users\%User%\AppData\Local\Programs\Python\Python37\Scripts> 
pip install pythonds 

安装屏幕截图

Easiest way to do this:

cd C:\Users\%User%\AppData\Local\Programs\Python\Python37\Scripts> 
pip install pythonds 

Screenshot of installing


回答 11

如果您使用的是python 3.4.1,则只需编写此行,from tkinter import *这会将模块中的所有内容放入程序的默认命名空间。实际上,不是像tkinter.Button您说的那样说一个按钮Button

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.Button you just type Button


声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。