Reputation: 454
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!
Upvotes: 12
Views: 69372
Reputation: 11
For python 2.7 use Cap Letters Tkinter but for >3.0 use small letter tkinter
Upvotes: 0
Reputation: 172
For python 2.7 it is Tkinter, however in 3.3.5 it is tkinter.
Upvotes: 0
Reputation: 85615
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.
Upvotes: 7
Reputation: 4213
Tkinter
(capitalized) refers to versions <3.0.
tkinter
(all lowecase) refers to versions ≥3.0.
Source: https://wiki.python.org/moin/TkInter
Upvotes: 12