The tkinter tutorial at tkdocs (http://www.tkdocs.com/tutorial/firstexample.html) shows these two lines at the beginning of every example.

from tkinter import *
from tkinter import ttk

Doesn't the first line import everything in the tkinter module? if so, why bother writing the second line?

EDIT: Just found an answer (kind of ) on the same page.
So I guess the real question would be "what's the difference between

import tkinter *

and

import tkinter

"

The tkinter tutorial at tkdocs (http://www.tkdocs.com/tutorial/firstexample.html) shows these two lines at the beginning of every example.

from tkinter import *
from tkinter import ttk

Doesn't the first line import everything in the tkinter module? if so, why bother writing the second line?

When performing an import * in Python, you as a developer actually have power over what is included in that "import all" statement. By populating your package with either an __all__.py file or an __all__ object within the package's code you're able to specify only particular objects to import.

Read up on this "import all" business here in the Python docs (which specifically talks about the __all__ convention)

EDIT: So what I'm trying to say is that the tkinter package probably doesn't have this ttk thingamabob included in the import all hubbub.

Vegaseat left this ttk code somewhere showing you the way module ttk should be imported and applied:

# exploring the Tkinter expansion module ttk notebook
# tested with Python 3.1 and Tkinter 8.5   by  vegaseat

import tkinter as tk
import tkinter.ttk as ttk

root = tk.Tk()
# use width x height + x_offset + y_offset (no spaces!)
root.geometry("%dx%d+%d+%d" % (300, 200, 100, 50))
root.title('test the ttk.Notebook')

nb = ttk.Notebook(root)
nb.pack(fill='both', expand='yes')

# create a child wdget for each page
f1 = tk.Frame(bg='red')
f2 = tk.Frame(bg='blue')
f3 = tk.Frame(bg='green')

# create the pages
nb.add(f1, text='page1')
nb.add(f2, text='page2')
nb.add(f3, text='page3')

# put a button widget on child f1
btn1 = tk.Button(f1, text='button1')
btn1.pack(side='left', anchor='nw', padx=3, pady=5)

root.mainloop()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.