2

I am trying to add a tab control to my GUI. However I'm getting this error: AttributeError: module tkinter has no attribute 'Notebook'. Other Tkinter objects work just fine, such as buttons, labels, canvas.

Any ideas what would cause this?

Also see same in REPL:

Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
>>> tkinter.notebook()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'tkinter' has no attribute 'notebook'
>>> tkinter.Notebook()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'tkinter' has no attribute 'Notebook'

Here's my code:

import tkinter as tk

class Tab1():
    def __init__(self, master):
        self.frame = tk.Frame(master)
        self.frame.pack(side=tk.LEFT, fill=tk.BOTH, expand=1)
        self.tabControl = tk.Notebook(self.frame)

I installed newer version of Python, and get same result:

Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
>>> tkinter.Notebook()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'tkinter' has no attribute 'Notebook'

2
  • 1
    The error is telling you exactly what the problem is: tkinter doesn't have a notebook. The ttk module does, however. Commented Mar 21, 2019 at 14:09
  • 1
    Bryan, thank you. None of the examples I had reviewed explained that Notebook was part of ttk which is a submodule of tkinter. They just used ttk so I had assumed it was the name they used when importing tkinter! Commented Mar 21, 2019 at 14:16

2 Answers 2

2

ttk is a submodule of tkinter; it needed to be imported. Better example to review than those I previously used: Notebook widget in Tkinter

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

Comments

0

It's because Notebook Widgets do not belong to Tkinter module. You need to import it from Tkinter. ttk. for example -

from Tkinter import ttk

ttk.notebook(root)... and so on

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.