Python Forum
Probem importing tkinter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Probem importing tkinter
#1
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
Reply
#2
If import Tkinter works you are using python 2, import tkinter is python 3.
Reply
#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
Reply
#4
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..
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020