Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
253 views
in Technique[技术] by (71.8m points)

python - Why does it say that no module named tkinter?

Good day. I installed pyhton 2 and python 3 in my laptop. And i'm using python 3 interpreter in writing my codes. Here is my code.

#! /usr/bin/python3

from tkinter import *

root = Tk()

theLabel = Label(root, text ="This is too easy")
theLabel.pack()

root.mainloop()

But when I double clicked the save file icon. It will say no module name tkinter. Can some one help me please?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

python 2 and python 3 use tkinter in a different way.

Note: Tkinter has been renamed to tkinter in Python 3. The 2to3 tool will automatically adapt imports when converting your sources to Python 3.

The above lines are from python documentation. Not sure if python is loading tkinter using python 2 or python 3..May be internal PYTHONPATH is messed up Rather try this,

try:
  import tkinter as tk
except ImportError:
  import Tkinter as tk

Note: In these situations where you use multiple versions of same modules, try using virualenv

Virtual Env


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...