Python Forum

Full Version: tkinter import problems on mac
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am working with tkinter, on a mac, and I am having trouble with imports. 
Everything works fine in IDLE, but if I try to run my code in Python Launcher (terminal/command line), I get all sorts of errors.
For example, this works just fine in IDLE:
from tkinter import *
import tkinter.scrolledtext as ScrolledText
At first, the error I got was "no module named tkinter". I finally realized that for it to work in Terminal (at least on my computer), I had to use 
from Tkinter import *
However, now I am getting errors with importing scrolledtext, and I am totally lost. I have tried:
import tkinter.scrolledtext as ScrolledText
import Tkinter.scrolledtext as ScrolledText
from tkinter.scrolledtext import scrolledtext
from Tkinter.scrolledtext import scrolledtext
I know it is possible to create this without scrolledtext, but I would like to avoid that if possible. Is there any way to make ScrolledText import in Terminal?
Tkinter is for python 2
and it's tkinter for python 3
if you have both installed your syntax needs to be such that you run the correct version of python.
On my Linux Mint 18.1 by default I have python 2.7.6
I also have python 3.5.2 installed.
There are some more differences between 2.x and 3.x
if your code is called mycode.py  if it's tkinter in your code try
python3 mycode.py
from the terminal
You might need to give the path to the code.
you can use:

try:
    import tkinter
except ImportError:
    import Tkinter
1st case for python 3,
2nd for 2.7

reverse if you mainly use 2.7