python 2.7 - no module named tkinter
i am on mac os x 10.8, using the integrated python 2.7. i try to learn about tkinter with tutorials like this for python 2.7 (explicitly not 3) they propose the following code:
from tkinter import * import tkinter.messagebox
however, this brings up the error:
ImportError: No module named tkinter
using import.Tkinter with a capital t seems to work, but further commands like
don't (neither does tkinter.messagebox). I've had this problem with lots of tutorials. what's the thing with the capital / non-capital "T", and how do i get my python to work like it does in the tutorials? Thanks in advance!
In Tkinter (uppercase) you do not have messagebox. You can use Tkinter.Message or import tkMessageBox
This code is an example taken from this tutorial:
import Tkinter import tkMessageBox top = Tkinter.Tk() def hello(): tkMessageBox.showinfo("Say Hello", "Hello World") B1 = Tkinter.Button(top, text = "Say Hello", command = hello) B1.pack() top.mainloop()
Your example code refers to a python installation >= py3.0. In Python 3.x the old good Tkinter has been renamed tkinter.
Tkinter (capitalized) refers to versions <3.0.
tkinter (all lowecase) refers to versions ≥3.0.
For python 2.7 it is Tkinter, however in 3.3.5 it is tkinter.
For python 2.7 use Cap Letters Tkinter but for >3.0 use small letter tkinter