0

Hello everyone and thank you for your help in advance.

I am trying to use tkinter library. When I open terminal type python3 and use

import tkinter
tkinter._test()

It works. Also when I type python and use

import Tkinter
Tkinter.TK()

It also works. My problem is when I install on my ubuntu 18.04 LTS IDE like for eg. Eric Python or VISUAL STUDIO etc. Under python2 or python3 I get same error and can not load tkinter ModuleNotFoundError: No module named 'Tkinter'

When I load my simple code I get this error:

Exception has occurred: ModuleNotFoundError

No module named 'Tkinter' File "/home/user234/Desktop/Program/start.py", line 1, in import Tkinter File "/usr/lib/python3.6/runpy.py", line 85, in _run_code exec(code, run_globals) File "/usr/lib/python3.6/runpy.py", line 96, in _run_module_code mod_name, mod_spec, pkg_name, script_name) File "/usr/lib/python3.6/runpy.py", line 263, in run_path pkg_name=pkg_name, script_name=fname) This is the code I use

import Tkinter
canvas = Tkinter.Canvas()
canvas.pack()
canvas.create_line(10, 100, 200, 100, 10, 200)

Any suggestions where could be problem? I could not google answer for this question.

0

I found solution. When using IDE you need to add this to your code to use tkinter library:

import tkinter as tk
root = tk.Tk()
root.mainloop()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.