Python Forum

Full Version: Probem importing tkinter
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi

I'm trying to teach my son Python programming... we're using Spyder on Ubuntu.

I'm trying to use this code...
from tkinter import *
import tkinter

tk = Tk()
canvas = Canvas(tk, width=500, height=400)
tk.title("drawing")
canvas.pack()

canvas.mainloop()
However,I keep getting this error

ImportError: No module named tkinter
I've tried installing python3-tk using apt-get but still no joy.

Any suggestions would be greatly appreciated.
Kind regards
Gary
If import Tkinter works you are using python 2, import tkinter is python 3.
And I have validated that as I am only using python 3.7 and I was able to copy that code and run it without issue. So if you do have python 3 loaded perhaps you are inadvertently still referencing python 2
tkinter is usually installed with the default install of python. Open up your teminal
and enter: python3
you should have an output similar but with your version:
Output:
Python 3.5.3 (default, Jan 19 2017, 14:11:04) [GCC 6.3.0 20170124] on linux Type "help", "copyright", "credits" or "license" for more information. >>>
then enter your import of tkinter
import tkinter
if no error it's installed..