Python 在 ubuntu 14.04 上安装 tkinter

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26702119/
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-19 00:54:04  来源:igfitidea点击:

Installing tkinter on ubuntu 14.04

pythonpython-2.7tkinterubuntu-14.04

提问by Mayank Jain

I want to run python code on Ubuntu 14.04, but when I execute it, it gives me the following error message

我想在 Ubuntu 14.04 上运行 python 代码,但是当我执行它时,它给了我以下错误消息

Traceback (most recent call last):
  File "main.py", line 2, in <module>
    from tkinter import *
ImportError: No module named tkinter

回答by the_dude

Try writing the following in the terminal:

尝试在终端中编写以下内容:

sudo apt-get install python-tk

Don't forget to actually import Tkinter module at the beginning of your program:

不要忘记在程序开始时实际导入 Tkinter 模块:

import Tkinter

回答by Elliott Frisch

Install the package python-tklike

python-tk像这样安装包

sudo apt-get install python-tk

That is described (with apt-cache search python-tkas)

被描述为 (with apt-cache search python-tkas)

Tkinter - Writing Tk applications with Python

回答by gon1332

If you're using Python 3then you must install as follows:

如果您正在使用,Python 3则必须按如下方式安装:

sudo apt-get update
sudo apt-get install python3-tk

Tkinter for Python 2(python-tk) is different from Python 3's (python3-tk).

Tkinter for Python 2( python-tk) 与Python 3's ( python3-tk) 不同。

回答by frfzone

In Ubuntu 14.04.2 LTS:

在 Ubuntu 14.04.2 LTS 中:

  1. Go to Software Center and remove "IDLE(using Python-2.7)".

  2. Install "IDLE(using Python-3.4)".

  1. 转到软件中心并删除“空闲(使用 Python-2.7)”。

  2. 安装“空闲(使用 Python-3.4)”。

Try again. This step worked for me.

再试一次。这一步对我有用。

回答by Aman Deep

First, make sure you have Tkinter module installed.

首先,确保你安装了 Tkinter 模块。

sudo apt-get install python-tk

In python 2 the package name is Tkinter not tkinter.

在 python 2 中,包名是 Tkinter 而不是 tkinter。

from Tkinter import *

ref: http://www.techinfected.net/2015/09/how-to-install-and-use-tkinter-in-ubuntu-debian-linux-mint.html

参考:http: //www.techinfected.net/2015/09/how-to-install-and-use-tkinter-in-ubuntu-debian-linux-mint.html

回答by PaulMest

To get this to work with pyenvon Ubuntu 16.04, I had to:

为了pyenv让它在 Ubuntu 16.04 上工作,我必须:

$ sudo apt-get install python-tk python3-tk tk-dev

Then install the version of Python I wanted via pyenv:

然后通过以下方式安装我想要的 Python 版本pyenv

$ pyenv install 3.6.2

Then I could import tkinter just fine:

然后我可以很好地导入 tkinter:

import tkinter