0
votes

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?

2
what do you mean "save file icon"? If you run this code, you should not be getting errors if python is installed correctly. Also, which platform are you using? please edit the question - Andrew
What exactly did you do when you tried to install tkinter for python3? - decltype_auto
@Andrew the icon of the program I save. - John Cruz
@Andrew - the icon of the saved program. When I save the program. I double click the icon of my program. Sorry for my english - John Cruz

2 Answers

3
votes

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

2
votes

you need to check the module name or package name before using it, do this

from Tkinter import *