I am trying to import Tkinter to my project using Python 2.7 and instead I get the error:
我试图使用Python 2.7将Tkinter导入我的项目,而是我得到错误:
ImportError: No module named tkinter
ImportError:没有名为tkinter的模块
Before anyone says it, I have tried both "Tkinter" and "tkinter" but have gotten the exact same message.
在任何人说出来之前,我已经尝试了“Tkinter”和“tkinter”,但却得到了完全相同的信息。
5 个解决方案
#1
4
First try using this code for your imports.
首先尝试使用此代码进行导入。
try: import Tkinter as tk # this is for python2except: import tkinter as tk # this is for python3
If this doesn't work, try reinstalling tkinter. If you don't know how to reinstall tkinter look at the tkinter installation page, here.
如果这不起作用,请尝试重新安装tkinter。如果您不知道如何重新安装tkinter,请查看tkinter安装页面。
#2
1
Some compilers have tkinter preinstalled. For example, if you use IDLE tkinter is preinstalled. As much as I know, if you use IDLE, you have to click a box in order to install tkinter.If you are not using IDLE, check whether tkinter/Tkinter is included in your Site Packages folder. Consider reinstalling the compiler/interpreter you are using.After you made sure it is installed the syntax you have to use depends on the version of Python you are using.I am not quite sure for Python 2, but I think you write:
有些编译器预装了tkinter。例如,如果您使用IDLE,则会预先安装tkinter。据我所知,如果您使用IDLE,则必须单击一个框才能安装tkinter。如果您没有使用IDLE,请检查您的Site Packages文件夹中是否包含tkinter / Tkinter。考虑重新安装正在使用的编译器/解释器。确定安装后,必须使用的语法取决于您使用的Python版本。我不太清楚Python 2,但我认为您写道:
import Tkinter
For Python 3 you write:
对于Python 3,你写道:
import tkinter
or the more often used:
或者更常用的:
from tkinter import *
#3
0
Had the same problem ,please try this;
有同样的问题,请试试这个;
from Tkinter import *
#4
0
You should install the tkinter
package for python. Tkinter has been renamed to tkinter in Python 3. The 2to3
tool will automatically adapt imports when converting your sources to Python 3.
你应该为python安装tkinter包。 Tkinter已经在Python 3中重命名为tkinter。在将源代码转换为Python 3时,2to3工具将自动调整导入。
Note: The following commands below are assuming that you run a Linux device.
注意:以下命令假定您运行Linux设备。
For Python 2:
对于Python 2:
pip install python-tksudo apt-get install python-tk
for Python 3:
对于Python 3:
pip install python3-tksudo apt-get install python3-tk
#5
0
If you are using Ubuntu or Debian OS try this:-
如果您使用的是Ubuntu或Debian OS,请尝试以下方法: -
sudo apt-get install python-tk
Or if you are using Python 3:-
或者,如果您使用的是Python 3: -
sudo apt-get install python3-tk
#1
4
First try using this code for your imports.
首先尝试使用此代码进行导入。
try: import Tkinter as tk # this is for python2except: import tkinter as tk # this is for python3
If this doesn't work, try reinstalling tkinter. If you don't know how to reinstall tkinter look at the tkinter installation page, here.
如果这不起作用,请尝试重新安装tkinter。如果您不知道如何重新安装tkinter,请查看tkinter安装页面。
#2
1
Some compilers have tkinter preinstalled. For example, if you use IDLE tkinter is preinstalled. As much as I know, if you use IDLE, you have to click a box in order to install tkinter.If you are not using IDLE, check whether tkinter/Tkinter is included in your Site Packages folder. Consider reinstalling the compiler/interpreter you are using.After you made sure it is installed the syntax you have to use depends on the version of Python you are using.I am not quite sure for Python 2, but I think you write:
有些编译器预装了tkinter。例如,如果您使用IDLE,则会预先安装tkinter。据我所知,如果您使用IDLE,则必须单击一个框才能安装tkinter。如果您没有使用IDLE,请检查您的Site Packages文件夹中是否包含tkinter / Tkinter。考虑重新安装正在使用的编译器/解释器。确定安装后,必须使用的语法取决于您使用的Python版本。我不太清楚Python 2,但我认为您写道:
import Tkinter
For Python 3 you write:
对于Python 3,你写道:
import tkinter
or the more often used:
或者更常用的:
from tkinter import *
#3
0
Had the same problem ,please try this;
有同样的问题,请试试这个;
from Tkinter import *
#4
0
You should install the tkinter
package for python. Tkinter has been renamed to tkinter in Python 3. The 2to3
tool will automatically adapt imports when converting your sources to Python 3.
你应该为python安装tkinter包。 Tkinter已经在Python 3中重命名为tkinter。在将源代码转换为Python 3时,2to3工具将自动调整导入。
Note: The following commands below are assuming that you run a Linux device.
注意:以下命令假定您运行Linux设备。
For Python 2:
对于Python 2:
pip install python-tksudo apt-get install python-tk
for Python 3:
对于Python 3:
pip install python3-tksudo apt-get install python3-tk
#5
0
If you are using Ubuntu or Debian OS try this:-
如果您使用的是Ubuntu或Debian OS,请尝试以下方法: -
sudo apt-get install python-tk
Or if you are using Python 3:-
或者,如果您使用的是Python 3: -
sudo apt-get install python3-tk