12

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

import Tkinter.messagebox

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!

2
  • In the second case is it No module named Tkinter or No module named messagebox ? Commented Sep 10, 2013 at 21:41
  • the error goes like: import Tkinter.messagebox ImportError: No module named messagebox Commented Sep 10, 2013 at 21:43

4 Answers 4

12

Tkinter (capitalized) refers to versions <3.0.

tkinter (all lowecase) refers to versions ≥3.0.

Source: https://wiki.python.org/moin/TkInter

Sign up to request clarification or add additional context in comments.

Comments

7

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.

Comments

0

For python 2.7 it is Tkinter, however in 3.3.5 it is tkinter.

Comments

0

For python 2.7 use Cap Letters Tkinter but for >3.0 use small letter tkinter

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.